Search code examples
c#wpftextblock

How to get the content of a textblock and show it multiple times?


I am trying to make a program that helps me with checking on which lines there are errors on an arma 3 server. It currently looks like this:

I have a few problems. Every time I mark a "bug" and press the show button it comes up with this:

How do i get the content of the textbox? This is my code:

public partial class MainWindow : Window
{
    public double output = 0;
    public string test1 = "";
    public MainWindow()
    {
        InitializeComponent();
        textOutput.Text = output.ToString();
        textBugs.Text = test1;
    }

    private void buttonDecrease_Click(object sender, RoutedEventArgs e)
    {
        output--;
        textOutput.Text = output.ToString();
    }

    private void buttonIncrease_Click(object sender, RoutedEventArgs e)
    {
        output++;
        textOutput.Text = output.ToString();
    }

    private void buttonReset_Click(object sender, RoutedEventArgs e)
    {
        output = 0;
        test1 = "N/A";
        textOutput.Text = output.ToString();
        textBugs.Text = test1;
    }

    private void buttonBug_Click(object sender, RoutedEventArgs e)
    {
        test1 += textBugs.ContentStart.ToString();
    }

    private void buttonShow_Click(object sender, RoutedEventArgs e)
    {
        textBugs.Text = test1;
    }
}

Solution

  • This line is the problem.

    test1 += textBugs.ContentStart.ToString();
    

    ContentStart is a property on a RichTextBox with the type TextPointer. You're just assigning the string representation of this type to the string test1.

    To get the plain text from the RTB:

    test1 += textBugs.Text;