在我的 Prism 6 WPF 模块化应用程序中,我使用名为“CommonControlLibrary”的 WPF ControlLibrary 项目,该项目具有包含 ResourceDictionary 的“SwitchButtonStyle.xaml”文件。ResourceDictionary 用于在我的应用程序中设置单选按钮的样式。以下是我的应用程序结构:
下面我部分展示了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:
<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 中都是相同的,并且每个都需要使用 ResourceDistionary 中的 MainViewRadioButtonStyle 进行样式设置,该样式位于“CommonControlLibrary”中的“SwitchButtonStyle.xaml”中。如何在每个 RadioButton 的 XAML 中包含对 ResourceDictionary 的引用,以将“MainViewRadioButtonStyle”样式应用于 Prism 6 模块中的 RadioButton?请在“校准”RadioButton XAML 示例中向我展示。
1) 在视图顶部添加合并资源字典的 xaml 代码:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/CommonControlLibray;component/SwitchButtonStyle.xaml" />
2.) 为单选按钮添加 Style 属性:
<RadioButton Style={StaticResource MainViewRadioButtonStyle}" ...
or
为单选按钮添加隐式样式:
<Style TargetType="RadioButton" BasedOn="{StaticResource MainViewRadioButtonStyle}" />
隐式样式将应用于all视图上的单选按钮
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)