title: treeview item validation
body: <p>I'm trying to validate items inside a treeview. The main idea is that a user selects an object from the tree and that loads its details which can be edited. That's all working fine as I've got <code>INotifyPropertyChanged</code> hooked up but... my model has validation logic hooked up (<code>IDataErrorInfo</code>) and I'd like to show it in the treeview as well (highlight the item(s) which have validation errors).</p>
  
  <p>I've tried some things already but I just can't figure out where to put the Validation in the binding to make it work like I would like it to.</p>
  
  <p>My Validation ControlTemplate:</p>
  
  <pre><code>&lt;ControlTemplate x:Key="validationTemplate"&gt;
              &lt;StackPanel Orientation="Horizontal"&gt;
                  &lt;AdornedElementPlaceholder x:Name="MyAdorner" /&gt;
                  &lt;Image
                                              MaxHeight="{Binding ElementName=MyAdorner, Path=ActualHeight}" 
                                              MaxWidth="20"
                                              Source="{Binding Source={StaticResource ValidationIcon}, Converter={StaticResource UriConverter}}" 
                                              Margin="1" RenderOptions.BitmapScalingMode="HighQuality"
                                              VerticalAlignment="Center" HorizontalAlignment="Center" /&gt;
              &lt;/StackPanel&gt;
          &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>The treeView:</p>
  
  <pre><code>&lt;TreeView ItemsSource="{Binding Path=ProductCategories}"
                Name="treeView" SelectedItemChanged="treeView_SelectedItemChanged"&gt;           
                  &lt;TreeView.ItemTemplate&gt;
                      &lt;HierarchicalDataTemplate DataType="{x:Type data:ProductCategory}"
                                        ItemsSource="{Binding Path=ProductCategories}"&gt;
                          &lt;StackPanel Orientation="Horizontal"&gt;
                              &lt;StackPanel.Style&gt;
                                  &lt;Style TargetType="StackPanel"&gt;
                                      &lt;Style.Triggers&gt;
                                          &lt;Trigger Property="Validation.HasError" Value="True"&gt;
                                              &lt;Setter Property="ToolTip"
                                                      Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/&gt;
                                              &lt;Setter Property="Validation.ErrorTemplate"
                                                      Value="{StaticResource validationTemplate}" /&gt;
                                          &lt;/Trigger&gt;
                                      &lt;/Style.Triggers&gt;
                                  &lt;/Style&gt;
                              &lt;/StackPanel.Style&gt;
                              &lt;StackPanel.BindingGroup&gt;
                                  &lt;BindingGroup /&gt;
                              &lt;/StackPanel.BindingGroup&gt;
                              &lt;StackPanel.ToolTip&gt;
                                  &lt;TextBlock Margin="2" Text="{Binding Path=Description}" /&gt;
                              &lt;/StackPanel.ToolTip&gt;
                              &lt;TextBlock Text="{Binding Path=Name}" FontSize="10" FontWeight="Medium" /&gt;
                              &lt;TextBlock Text="{Binding Path=ProductCount, StringFormat='   ({0})'}" /&gt;
                          &lt;/StackPanel&gt;
                      &lt;/HierarchicalDataTemplate&gt;
                  &lt;/TreeView.ItemTemplate&gt;
              &lt;/TreeView&gt;
  </code></pre>
  
  <p>Basically I'm trying to put a little icon next to the item in the treeview if the underlying Model has a validation error.</p>
  
  <p>I've tried playing around with BindingGroup but that's a new topic for me so I'm not sure if that is even the way to go.</p>
  
  <p>Any ideas?</p>