开发者

In XAML is it possible to set a ResourceDictionary and Style in UserControl.Resources side-by-side?

Is it possible to set an inline style when I've already set a ResourceDictionary?

Here is what I've already set...

 <UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/My.Project.Common.Desktop;component/Themes/StandardStyles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </UserControl.Resources>

Here are the styles I need to add to the UserControl.Resources node...

 <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>
      开发者_StackOverflow社区          <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>

I need it to be set these styles at a UserControl level because they are bound to the data context.

How do I do this?


you can add resources like this

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜