title: Conditionally binding Foreground to a boolean
body: <p>I have a Treeview showing Xml data where each element is wrapped in a class that exposes IsExpanded, the wrapped XElement's Name and Value and a boolean MatchesFilter which is set if the element matches a specific filter; I'd like to change the foreground color if MatchesFilter is true. </p>
  
  <p>What I currently have is:</p>
  
  <pre><code>&lt;TreeView.ItemTemplate&gt;
      &lt;HierarchicalDataTemplate ItemsSource="{Binding Children}"&gt;
          &lt;StackPanel Orientation="Horizontal"&gt;
              &lt;TextBlock Width="110" Foreground="Blue" Text="{Binding Name}" /&gt;
              &lt;TextBlock Foreground="{Binding Foreground}" Text="{Binding Value}" /&gt;
          &lt;/StackPanel&gt;
      &lt;/HierarchicalDataTemplate&gt;
  &lt;/TreeView.ItemTemplate&gt;
  </code></pre>
  
  <p>where the Foreground color is being set in the code-behind, which works just fine but is hardly in the spirit of WPF! How do I do this properly?</p>
  
  <p>Edit: Thank you, exactly like that, now I know which chapter to read.</p>