ItemsSource がクラスである StaticResource にバインドされている TreeView があります。これは私にとってはうまくいきましたが、現在、TreeView の最下位レベルを異なる値で更新する関数があり、この更新をすぐに表示する必要があります。ツリー内のチェックボックスの IsChecked をモデル内の値にバインドしたり、テキストブロック テキストをモデル内の値にバインドするなど、同様のタスクを達成しました。
XAML で TreeView を参照するためのコードを次に示します。
<!-- TREE VIEW ON LEFT HAND SIDE. LOADS TREEVIEWPARENTS, WHICH HAVE ORDER ATTRIBUTE CHILDREN -->
<DockPanel Name="test1" Margin="10,10,0,10" VerticalAlignment="Stretch" Grid.Row="3" Grid.RowSpan="6" Grid.Column="0">
<DockPanel.Resources>
<local:CheckBoxCommand x:Key="cbc"></local:CheckBoxCommand>
<src:TreeViewFilter x:Key="MyList" />
<!-- PARENTS OF THE TREEVIEW -->
<HierarchicalDataTemplate DataType="{x:Type src:TreeViewParent}" ItemsSource="{Binding Path=OrderAttributes}">
<TextBlock Text="{Binding Path=NameAndCount}" FontSize="24"/>
</HierarchicalDataTemplate>
<!-- CHILDREN OF THE PARENTS. THESE ORDER ATTRIBUTES HAVE CHILDREN OF THEIR OWN -->
<HierarchicalDataTemplate DataType="{x:Type src:OrderAttribute}" ItemsSource="{Binding Path=OrderAttributes}">
<StackPanel Name="test" Orientation="Horizontal" VerticalAlignment="Center">
<CheckBox Command="{StaticResource cbc}"
CommandParameter="{Binding Path=NameAndParent}" Visibility="{Binding Path=CheckBoxVisible}" IsChecked="{Binding Path=isChecked}" VerticalAlignment="Center">
</CheckBox>
<TextBlock Text="{Binding Path=NameAndCount}" FontSize="16"/>
</StackPanel>
</HierarchicalDataTemplate>
</DockPanel.Resources>
<TreeView Name="treeView1" BorderThickness="2" ItemsSource="{Binding Source={StaticResource MyList}, NotifyOnSourceUpdated=True}" TreeViewItem.Selected="filterByBatchStatus"/>
</DockPanel>
ご覧のとおり、ItemsSource は StaticResource MyList にバインドされています。これは実際にはクラス TreeViewFilter の Name のキーにすぎません。これが私にとってうまくいった理由は、ツリーに含まれる「TreeViewParents」と「OrderAttributes」がすべて TreeViewFilter クラスのコンストラクターで作成されるためです。しかし今、ツリーの最下位階層の値を更新して、それらを視覚的に表示できるようにしたいと考えています。
私の推測では、INotifyPropertyChanged を使用し、propertyChanged イベントまたはそれらの行に沿って何かを起動して、視覚的な更新で他のバインディングを行った方法と同様にこれを行うことができますか? 何か案は?
(また、バインディングの NotifyOnSourceUpdated=True は、この問題をいじっていたもので、どのように機能するかわかりません)