動的ContentControl
に設定する必要があるものがあります。ContentTemplate
そこで、2を記述し、ビューモデルのブール依存関係プロパティが変更されたときにトリガーが起動して適切なテンプレート(dt1 / dt2)を設定するようDataTemplates
にスタイルを設定することにしました(true / false)。ContentControl
ただし、問題は、ブール型プロパティが主にに設定されているtrue
場合、データテンプレートは常にになりdt1
、プロパティをfalse
変更してもテンプレートがに変更されないことdt2
です。
データトリガーはブール依存関係プロパティにバインドされているため、プロパティを変更するとトリガーが起動されませんか?
ノート:
- クリックイベント
MyView
を変更するボタンがあります。BooleanDependencyProp
MyViewModel
を実装するインターフェースから継承しますINotifyPropertyChanged
。
Xaml:
<UserControl x:Class="Views.MyView">
...
<StackPanel>
<ContentControl Content="{Binding RelativeSource={RelativeSource AncestorType=MyView}, Path=MyViewModel}">
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Style.Triggers>
<DataTrigger Binding="{Binding BooleanDependencyProp}" Value="true">
<Setter Property="ContentTemplate">
<Setter.Value>
<dt1 ... />
</Setter.Value>
</Setter>
<DataTrigger Binding="{Binding BooleanDependencyProp}" Value="false">
<Setter Property="ContentTemplate">
<Setter.Value>
<dt2 ... />
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
</StackPanel>