I have a WPF Application and I'd like to add a button that will open a Console window and display Console.WriteLine messages. It doesn't have to be a CMD Console, just a display box like an emulated one.
My idea was to create a Window, Console.xaml with a ScrollViewer/TextBox and redirect the WriteLine using something like this but I can't get it to work:
XAML
<ScrollViewer Name="Scroller" Margin="0" Background="#FF000128">
<TextBlock Name="OutputBlock" Foreground="White" FontFamily="Consolas"/>
</ScrollViewer>
C#
System.Diagnostics.Debug.WriteLine("hello", console.OutputBlock.Text);
Constructor
public Console(MainWindow mainwindow)
{
InitializeComponent();
this.mainwindow = mainwindow;
}
An Example I made in Photoshop with made up log text
I tried this solution, but I'm not sure how to use it. I get an OnStartup "no suitable method found to override" error:
https://stackoverflow.com/a/10416069/6806643
I also tried this solution. I copy exact but it is filled with errors:
https://stackoverflow.com/a/14957478/6806643
This code gives no errors but I don't know how it's supposed to be used: