我希望根据动态资源的值切换控件样式。
<Image x:Name="leftImg" Stretch="Fill" Style="{StaticResource BookendImageStyle}" > <Image.Triggers> <DataTrigger Binding="{DynamicResource BlackAndWhite}" Value="True"> <Setter TargetName="leftImg" Property="Style" Value="{StaticResource BookendImageStyleBW}" /> </DataTrigger> </Image.Triggers> </Image>
这编译得很好,但是在运行时我得到了以下异常:
A 'DynamicResourceExtension' cannot be set on the 'Binding' property of type 'DataTrigger'. A 'DynamicResourceExtension' can only be set on a DependencyProperty of a DependencyObject.
我想做什么是可能的吗?我只是语法不对吗?我应该换一种方式吗?
编辑我已将代码更改为:
<DataTemplate x:Key="ViasTemplate"> <StackPanel Orientation="Horizontal"> <Border Padding="{Binding ElementName=templateTest, Path=DataContext.GridRow.LeftBondIndent}" Width="50"> <Image x:Name="leftImg" Stretch="Fill" Style="{StaticResource BookendImageStyle}" > <Image.Triggers> <DataTrigger Binding="{Binding Source={StaticResource BlackAndWhite}}" Value="True"> <Setter TargetName="leftImg" Property="Style" Value="{StaticResource BookendImageStyleBW}" /> </DataTrigger> </Image.Triggers> </Image>
但现在有个例外:
Triggers collection members must be of type EventTrigger
谢谢
618夏日盛惠
2核2G云服务器首年95元,GPU云服务器低至9.93元/天,还有更多云产品低至0.1折…
<Image x:Name="leftImg" Stretch="Fill" Style="{StaticResource BookendImageStyle}" >