2

I am making a test program that should present logged data for the user on the screen. What I am trying to do now is to process each message as it comes whereafter I present it on the screen where different parts of the message should be presented in different colors depending on the result. How should I do this if I want to use the MVVM pattern? My idea was to use the RichTextBox but I am not sure on how to catch the actual changes and then only color parts of it.

My first idea was to use a TextBlock. If it binds with Message, where Message returns a string of all the so far logged data I assume it will not just update the changes of the Message string but rather all the logged data. Would this be terribly inefficient when having a lot of log entries?

        <TextBlock
        x:Name="logTxt"
        Grid.Row="0" Grid.Column="0"
        Text="{Binding Path=Message, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" Background="White"/>

Now if I would like to use the RichTextBox instead, and then only update it with the new data, then could I color the different parts with use of XAML-code or do I have to write it as C# code? Would that be to go against the MVVM pattern? I have searched for a solution but did not really find an explanation that could clarify this for me as I am quite new to C# and MVVM overall.

Lokinin
  • 71
  • 1
  • 1
  • 8

0 Answers0