我正在尝试创建一个像IRC一样的聊天窗口,其中内容从下到上显示,就像任何创建的聊天窗口一样。来自底部的WPF RichTextBox文本
这是我的XAML,没有什么特别之处它
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ee="http://schemas.microsoft.com/expression/2010/effects" xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" x:Class="TestChat.Chat"
Title="Chat" Height="700" Width="400" WindowStyle="ThreeDBorderWindow" ResizeMode="CanMinimize">
<Grid>
<RichTextBox x:Name="txtChat" HorizontalAlignment="Left" Height="644" Margin="0,10,0,0" VerticalAlignment="Top" Width="388" VerticalScrollBarVisibility="Auto">
<FlowDocument />
</RichTextBox>
</Grid>
</Window>
,我有一个BackgroundWorker添加文本到它
private void SendWorkerComplete(object s, ProgressChangedEventArgs args)
{
txtChat.AppendText(args.UserState.ToString());
txtChat.ScrollToEnd();
}
private void SendWorker_DoWork(object sender, DoWorkEventArgs e)
{
SendWorker.ReportProgress(0, (string)e.Argument);
}
的VerticalContentAlignment属性设置为底部不会呈现内容这样,这怎么可能呢?有没有财产或它必须以编程方式完成?
这是一个类似的要求。不完全按照您指定的,但它可能适用于您:http://stackoverflow.com/questions/10308475/how-can-i-make-a-richtextbox-scroll-to-the-end-when-i- add-a-new-line – JamieMeyer
只能滚动到底部,但如果richtextbox是空的,没有用于重现此行为,我想我可以添加一堆空行并滚动结束,然后再将输出附加到它以重现这,但我正在寻找一个更优雅的方式来做到这一点,谢谢 – FuuRe
你能告诉我们你使用的xaml吗? – StillLearnin