Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF RichTextBox text from bottom

I'm trying to make a chat window, like IRC, in which the contents are shown from bottom to top, just like any chat window ever created.

This is my xaml, nothing fancy about it

<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>

And i have a backgroundworker adding text to it

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);
}

The VerticalContentAlignment property set to bottom does not render the contents this way, how could this be done? is there a property for it or it has to be done programmatically?

like image 465
FuuRe Avatar asked Apr 21 '26 03:04

FuuRe


1 Answers

Why bother with a RichTextBox? Just use a regular TextBox.

<Grid>
    <TextBox x:Name="txtChat" VerticalScrollBarVisibility="Auto" Margin="10" Text="Hello" VerticalContentAlignment="Bottom" />
</Grid>
like image 73
StillLearnin Avatar answered Apr 22 '26 15:04

StillLearnin