2
votes

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:

enter image description here

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

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>

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

1 Answers

0
votes

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.) Add a Style attribute to you radio button:

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

or

Add an inplicit style for radio buttons:

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

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