Binding 値に基づいて ContentTemplate を適用しようとしています。問題は、それが機能していないことです。
TemplateA と呼ばれるデフォルトのテンプレートがあり、データバインドされた値 (TemplateA または TemplateB のいずれか) に基づいてスタイルを表示したいと考えています。
デフォルト テンプレートをコメント アウトすると、どちらのテンプレートも選択されません。
データバインドされた値を確認しました。値は問題ありません。
私が間違っているところがわかりますか?
これがListDataViewです
<CollectionViewSource x:Key="ListDataView" />
Window の Resources セクション内にあり、ListDataView はコード内で ObservableCollection にアタッチされています。
<DataTemplate x:Key="TemplateA">
<TextBlock Text="Template A" />
</DataTemplate>
<DataTemplate x:Key="TemplateB">
<TextBlock Text="Template B" />
</DataTemplate>
<ContentControl x:Name="LISTINGCONTROLA">
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="ContentTemplate" Value="{StaticResource TemplateA}" />
<Style.Triggers>
<DataTrigger Binding="{Binding Source={StaticResource ListDataView}, Path=ListType}" Value="TEMPLATEA">
<Setter Property="ContentTemplate" Value="{StaticResource TemplateA}" />
</DataTrigger>
<DataTrigger Binding="{Binding Source={StaticResource ListDataView}, Path=ListType}" Value="TEMPLATEB">
<Setter Property="ContentTemplate" Value="{StaticResource TemplateB}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>