如何使用单独的 WpfControlLibrary 中的 ResourceDictionary 将样式设置为 Prism 6 模块中的 RadioButton? [英] How to use ResourceDictionary from separate WpfControlLibrary to set style to RadioButton in Prism 6 Module?

查看:61
本文介绍了如何使用单独的 WpfControlLibrary 中的 ResourceDictionary 将样式设置为 Prism 6 模块中的 RadioButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Prism 6 WPF 模块化应用程序中,我使用名为CommonControlLibrary"的 WPF ControlLibrary 项目,其中包含包含 ResourceDictionary 的SwitchButtonStyle.xaml"文件.ResourceDictionary 用于在我的应用程序中设置 RadioButtons 的样式.以下是我的应用程序结构:

In my Prism 6 WPF modular application I use WPF ControlLibrary project called 'CommonControlLibrary' which has 'SwitchButtonStyle.xaml' file comprising the ResourceDictionary.The ResourceDictionary is for styling of RadioButtons in my application. Below is my application structure:

下面我部分显示了 ResourceDictionary.

Below I partially display the ResourceDictionary.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:local="clr-namespace:CommonControlLibrary"
                xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                mc:Ignorable="d" 
                xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" >

<!--Style for view-switching radiobuttons-->
<Style x:Key="MainViewRadioButtonStyle" TargetType="RadioButton">
    <Setter Property="Background" Value="{x:Null}"/>
    <Setter Property="Foreground" Value="#FF483D8B"/>
    <Setter Property="Padding" Value="3"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="FontSize" Value="12"/>
    <Setter Property="BorderBrush" Value="#FF6A5ACD" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="RadioButton">
                <Grid>
    . . . . . . . . . . . . . . . .

我的应用程序授权"和校准"中有两个 Prism 6 模块(见上图).每个模块都有对应的 View 和 RadioButton 来切换到那个 View.下面我显示了用于 RadioButton 切换到校准"视图的 XAML:

There are two Prism 6 Modules in my application 'Authorisation' and 'Calibration' (see picture above). Each module has corresponding View and RadioButton to switch to that View. Below I display XAML for RadioButton switching to 'Calibration' View:

<UserControl x:Class="Calibration.Views.CalibrationNavigationItemView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:prism="http://prismlibrary.com/"
         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
         prism:ViewModelLocator.AutoWireViewModel="True">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>

    <RadioButton GroupName="MainNavigation" IsChecked="{Binding Path=IsChecked, Mode=TwoWay}"
                 AutomationProperties.AutomationId="CalibrationRadioButton">
        Calibration
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Checked">
                <prism:InvokeCommandAction Command="{Binding NavigateToCalibrationCommand}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </RadioButton>
</Grid>

这两个 RadioButton 在 XAML 中是相同的,并且每个 RadioButton 都需要使用 MainViewRadioButtonStyle 来自 ResourceDistionary 的样式,该样式位于CommonControlLibrary"中的SwitchButtonStyle.xaml"中.如何在每个 RadioButton 的 XAML 中包含对 ResourceDictionary 的引用,以将MainViewRadioButtonStyle"样式应用于 Prism 6 模块中的 RadioButton?请在校准"单选按钮 XAML 示例中向我展示.

Both of the RadioButtons are identical in XAML and each of them needs to be styled with MainViewRadioButtonStyle from ResourceDistionary that is in 'SwitchButtonStyle.xaml that is in 'CommonControlLibrary'. How can I include the reference to the ResourceDictionary in XAML of each RadioButton to apply 'MainViewRadioButtonStyle' style to the RadioButton that is in Prism 6 Module? Please show me it on example of 'Calibration' RadioButton XAML.

推荐答案

1) 在视图顶部为合并的资源字典添加 xaml 代码:

1) On top of the view add xaml code for a merged resource dictionary:

<UserControl.Resources>

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>

            <ResourceDictionary Source="pack://application:,,,/CommonControlLibray;component/SwitchButtonStyle.xaml" />

2.) 为单选按钮添加样式属性:

2.) Add a Style attribute to you radio button:

<RadioButton Style={StaticResource MainViewRadioButtonStyle}" ...

为单选按钮添加隐式样式:

Add an inplicit style for radio buttons:

<Style TargetType="RadioButton" BasedOn="{StaticResource MainViewRadioButtonStyle}" />

隐式样式将应用于视图上的所有 RadioButtons

The implicit style will be applied to all RadioButtons on the view

这篇关于如何使用单独的 WpfControlLibrary 中的 ResourceDictionary 将样式设置为 Prism 6 模块中的 RadioButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆