title: ColorFul Text For Logging In Wpf C#
body: <p>I have a wpf app for for logging the error, general information and warning. These information also get displayed to the user in a text block of app so user can also see the errors and other information.</p>
  <p>But right now the color for the text for error warning and success is hard coded as dark grey.</p>
  <p>The job I have to do is to make it displayed in different colors Example (Success should be displayed in green color, Error should be red and general info in dark gray). I tried data binding but I can not achieve this. I need some help in this.
  Below I am sharing relevant code needed.</p>
  <p>MainWindow.Xaml Code</p>
  <pre><code>ListView Height=&quot;230&quot;
                        ItemsSource=&quot;{Binding EventLogList}&quot;&gt;
                  &lt;ListView.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;WrapPanel Width=&quot;560&quot;&gt;
                              &lt;TextBlock Foreground=&quot;DarkGray&quot;
                                         Text=&quot;{Binding}&quot;
                                         TextWrapping=&quot;Wrap&quot;/&gt;
                          &lt;/WrapPanel&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ListView.ItemTemplate&gt;
              &lt;/ListView&gt;
  </code></pre>
  <p>MainWindowViewModel.cs</p>
  <pre><code>public ObservableCollection&lt;string&gt; EventLogList
      {
          get =&gt; _eventLogList;
          set =&gt; Set(ref _eventLogList, value);
      }
  protected sealed override void LogInfoEvent(string msg)
      { 
  
          EventLogList.Insert(0, $&quot;{_logDate} [Info]: {msg}&quot;);
          base.LogInfoEvent(msg);
      }
  
      protected sealed override void LogErrorEvent(string msg, Exception exception = null)
      {
          if (IsScanningMode)
              StopScanningExecuteAsync();
  
          EventLogList.Insert(0, $&quot;{_logDate} [Error]: {msg}&quot;);
          base.LogErrorEvent(msg, exception);
          
      }
  </code></pre>