I'm working on a project and have decided to use UWP instead of using winforms (which I am more comfortable with). I have a very simple TextBox
that I am using as a way to log data being sent and received. Here is a simple example of what it looks like:
Here is what the XAML code for it:
<Grid>
<TextBlock HorizontalAlignment="Left" Margin="18,862,0,0" Text="Logs " TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBox x:Name="LogsTextBox" Margin="18,886,18,0" Text="Welcome to Tiger" TextWrapping="Wrap" VerticalAlignment="Top" Height="88" FontFamily="Courier New" FontSize="12" AcceptsReturn="True" ScrollViewer.VerticalScrollBarVisibility="Visible" IsReadOnly="True"/>
</Grid>
At the current moment of time, my TextBox
is wrapped by the default Grid
that I got when I first started the project.
Here is a look at the method used to add lines to the LogsTextBox
/// <summary>
/// A method used to log data to the LogsTextBox
/// </summary>
/// <param name="LogString">The string to be logged</param>
private void Log(string LogString)
{
string TimeString = DateTime.Now.ToString("hh-mm-ss-tt");
LogsTextBox.Text += $"\n[{TimeString}]: {LogString}";
}
As can be seen in this image the data being logged is now larger than the height of the TextBox
. Is there anyway I could make it so that every time the method Log
is called, the LogsTextBox
would auto scroll to the end?
I've found a couple of solutions on here but they didnt seeme to work for me. Namely these:
Any help I could get would be greatly appreciated