我正在尝试制作一个聊天窗口,类似于IRC,其中内容从底部向上显示,就像任何已创建的聊天窗口一样。
这是我的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>
我有一个背景工作者正在将文本添加到它上面。
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 属性设置为 bottom 并不会以此方式呈现内容,应该如何处理?有属性可以实现吗,还是必须在程序中完成?