在我的Prism 6 WPF模块化应用程序中,我使用名为“CommonControlLibrary”的WPF ControlLibrary项目,其中包含ResourceDictionary的“SwitchButtonStyle.xaml”文件.ResourceDictionary用于在我的应用程序中设置RadioButtons的样式。以下是我的申请结构:
下面我部分展示了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。下面我显示XAML for RadioButton切换到'Calibration'视图:
<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>
两个RadioButtons在XAML中是相同的,并且每个都需要使用ResourceDistionary中的MainViewRadioButtonStyle进行样式设置,该主题位于'CommonControlLibrary'中的'SwitchButtonStyle.xaml'中。如何在每个RadioButton的XAML中包含对ResourceDictionary的引用,以将'MainViewRadioButtonStyle'样式应用于Prism 6模块中的RadioButton?请在“校准”RadioButton XAML的示例中向我展示。
答案 0 :(得分:0)
1)在视图的顶部添加合并资源字典的xaml代码:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/CommonControlLibray;component/SwitchButtonStyle.xaml" />
2。)为你的单选按钮添加一个Style属性:
<RadioButton Style={StaticResource MainViewRadioButtonStyle}" ...
或
为单选按钮添加隐式样式:
<Style TargetType="RadioButton" BasedOn="{StaticResource MainViewRadioButtonStyle}" />
隐式样式将应用于视图所有 RadioButtons