当我已经设置了ResourceDictionary时,是否可以设置内联样式?
这是我已经设置的…
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/My.Project.Common.Desktop;component/Themes/StandardStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
下面是我需要添加到UserControl的样式。资源节点… <Style x:Key="MessageErrorIcon" TargetType="{x:Type Rectangle}">
<Style.Triggers>
<DataTrigger Binding="{Binding Icon}" Value="Asterisk">
<Setter Property="Fill" Value="{DynamicResource MessageOverlayInformationIcon}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Icon}" Value="Error">
<Setter Property="Fill" Value="{DynamicResource MessageOverlayErrorIcon}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Icon}" Value="Exclamation">
<Setter Property="Fill" Value="{DynamicResource MessageOverlayExclamationIcon}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Icon}" Value="Hand">
<Setter Property="Fill" Value="{DynamicResource MessageOverlayErrorIcon}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Icon}" Value="Information">
<Setter Property="Fill" Value="{DynamicResource MessageOverlayInformationIcon}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Icon}" Value="Question">
<Setter Property="Fill" Value="{DynamicResource MessageOverlayQuestionIcon}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Icon}" Value="Stop">
<Setter Property="Fill" Value="{DynamicResource MessageOverlayErrorIcon}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Icon}" Value="Warning">
<Setter Property="Fill" Value="{DynamicResource MessageOverlayExclamationIcon}"/>
</DataTrigger>
</Style.Triggers>
</Style>
我需要在UserControl级别设置这些样式,因为它们被绑定到数据上下文。
我该怎么做?
你可以添加这样的资源
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/My.Project.Common.Desktop;component/Themes/StandardStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="MessageErrorIcon"
TargetType="{x:Type Rectangle}">
<Style.Triggers>
<DataTrigger Binding="{Binding Icon}"
Value="Asterisk">
<Setter Property="Fill"
Value="{DynamicResource MessageOverlayInformationIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding Icon}"
Value="Error">
<Setter Property="Fill"
Value="{DynamicResource MessageOverlayErrorIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding Icon}"
Value="Exclamation">
<Setter Property="Fill"
Value="{DynamicResource MessageOverlayExclamationIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding Icon}"
Value="Hand">
<Setter Property="Fill"
Value="{DynamicResource MessageOverlayErrorIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding Icon}"
Value="Information">
<Setter Property="Fill"
Value="{DynamicResource MessageOverlayInformationIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding Icon}"
Value="Question">
<Setter Property="Fill"
Value="{DynamicResource MessageOverlayQuestionIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding Icon}"
Value="Stop">
<Setter Property="Fill"
Value="{DynamicResource MessageOverlayErrorIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding Icon}"
Value="Warning">
<Setter Property="Fill"
Value="{DynamicResource MessageOverlayExclamationIcon}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
</UserControl.Resources>