【发布时间】:2016-06-14 21:37:37
【问题描述】:
我为应用程序中的所有图像设置了默认样式(放入应用程序资源中):
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Setter Property="Opacity" Value="0.3"/> <!--To obviously see that it works-->
<Setter Property="RenderOptions.BitmapScalingMode" Value="HighQuality" />
<Setter Property="SnapsToDevicePixels" Value="True" />
</Style>
</ResourceDictionary>
如果我在其他地方有类似风格的图片
<Image>
<Image.Style>
<Style TargetType="{x:Type Image}">
... set some other properties here
</Style>
</Image.Style>
</Image>
未应用基本样式。如果我放一个
BasedOn="{StaticResource {x:Type Image}}"
一切都按(我)预期的那样工作。
有没有办法应用默认样式而无需遍历我的所有 xaml 并将 BasedOn 添加到每个样式图像?
编辑:
我经常有一些数据触发器,比如:
<Image>
<Image.Style>
<Style TargetType="{x:Type Image}" >
<Style.Triggers>
<DataTrigger Binding="{Binding Type}" Value="VAR1">
<Setter Property="Source" Value="/MyApp;component/Resources/Var1.png"/>
</DataTrigger>
<DataTrigger Binding="{Binding Type}" Value="VAR2">
<Setter Property="Source" Value="/MyApp;component/Resources/Var2.png"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
【问题讨论】: