私はツリービュー内のアイテムを検証しようとしています。主な考え方は、ユーザーがツリーからオブジェクトを選択し、そのオブジェクトが編集可能な詳細をロードすることです。 INotifyPropertyChanged
が接続されているので、それはすべてうまくいきますが...私のモデルは検証ロジックを持っています(IDataErrorInfo
)、ツリービューにも表示したいと思います(検証エラーがある項目を強調表示します) )。treeview item validation
私はすでにいくつかのことを試してきましたが、私が好きなように動作させるためにバリデーションをどこに置くべきかわかりません。
私の検証のControlTemplate:
<ControlTemplate x:Key="validationTemplate">
<StackPanel Orientation="Horizontal">
<AdornedElementPlaceholder x:Name="MyAdorner" />
<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" />
</StackPanel>
</ControlTemplate>
ツリービュー:基礎となるモデルは、検証エラーを持っている場合、私は、ツリービューでアイテムの横に小さなアイコンを置くしようとしている。基本的
<TreeView ItemsSource="{Binding Path=ProductCategories}"
Name="treeView" SelectedItemChanged="treeView_SelectedItemChanged">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type data:ProductCategory}"
ItemsSource="{Binding Path=ProductCategories}">
<StackPanel Orientation="Horizontal">
<StackPanel.Style>
<Style TargetType="StackPanel">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
<Setter Property="Validation.ErrorTemplate"
Value="{StaticResource validationTemplate}" />
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Style>
<StackPanel.BindingGroup>
<BindingGroup />
</StackPanel.BindingGroup>
<StackPanel.ToolTip>
<TextBlock Margin="2" Text="{Binding Path=Description}" />
</StackPanel.ToolTip>
<TextBlock Text="{Binding Path=Name}" FontSize="10" FontWeight="Medium" />
<TextBlock Text="{Binding Path=ProductCount, StringFormat=' ({0})'}" />
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
。
私はBindingGroupで遊んでみましたが、それは私の新しいトピックです。だから私はそれが行く方法であるか分かりません。
アイデア?