XAML WP8 'TextBlock'向下滚动

本文关键字:滚动 TextBlock XAML WP8 | 更新日期: 2023-09-27 18:02:11

好的,我在Windows Phone 8应用程序中有一个带有TextBlock的XAML页面。我的困境是:

我务实地添加了更多的内容(用内行格式化行)。添加(new Run…)到TextBlock。由于ScrollViewer,文本块目前从下向上填充,即一行在另一行之后出现在底部。我也会很好,他们开始从顶部出现,只要TextBlock将继续向下滚动(实际上这可能看起来更好)一旦它是满的。我的TextBlock在ScrollViewer中,如下所示:

    <Popup x:Name="send_message_xaml" Grid.Row="1" VerticalOffset="0" Width="750" Height="auto">
        <StackPanel Orientation="Vertical" Margin="0,0" Width="auto" Height="auto">
            <ScrollViewer Height="345" HorizontalAlignment="Left" Margin="0,0,0,0" Name="scrollViewer1" VerticalAlignment="Bottom" Width="420" VerticalScrollBarVisibility="Auto">
                <TextBlock x:Name="message_log"  Margin="40,50,0,0" TextWrapping="Wrap" Width="420" VerticalAlignment="Top" FontSize="22"/>
            </ScrollViewer>
            <TextBox x:Name="message_to_send" InputScope="Chat" Width="480" KeyDown="message_to_send_KeyDown" Margin="15,0"/>
        </StackPanel>
    </Popup>

我怎样才能得到文本块滚动,使最新附加的消息总是在底部?我发现了一堆这些线程,但迄今为止似乎没有解决我的问题。我是否需要在某个地方添加一些附加代码?

XAML WP8 'TextBlock'向下滚动

需要根据ScrollableHeight更新VerticalOffset。当您向TextBlock添加新的内联时,它的高度将发生变化,这将通知父ScrollViewer。因此,在向内联添加新项之后,运行Measure方法并更新VerticalOffset