I am developing in Expression Blend right now and have a single user control and two instances of it on my window. I want one of them to be blue and the other to be red. Instead of creating separate controls for each color, I could skin the control. I have created the two simple resource dictionaries that I want applied to each control, but I am stuck on how to assign a resource dictionary to the specific control. How do I tell each control where to get its resources from?
In Mainwindow.xaml, I create the user controls with:
<local:SystemButton Grid.Column="1" Margin="0"/> <local:SystemButton Grid.Column="2" Margin="0"/>
My resource dictionaries look like this, the only difference being colors:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <RadialGradientBrush x:Key="BackgroundBrush"> <GradientStop Color="#FFB42800" Offset="0"/> <GradientStop Color="#FF021426" Offset="1"/> </RadialGradientBrush> <SolidColorBrush x:Key="HighlightBrush" Color="#FFFFB39C"/> <RadialGradientBrush x:Key="LightBrush"> <GradientStop Color="Red" Offset="0"/> <GradientStop Color="#00FF0000" Offset="1"/> </RadialGradientBrush> <!-- Resource dictionary entries should be defined here. --> </ResourceDictionary>
Finally, my UserControl looks like this:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:System="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
x:Class="DesktopWeather.SystemButton"
x:Name="UserControl"
d:DesignWidth="50" d:DesignHeight="50">
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.25*"/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition Height="3.5*"/>
</Grid.RowDefinitions>
<Ellipse Margin="0" Grid.RowSpan="4" Grid.ColumnSpan="3" Fill="{DynamicResource BackgroundBrush}"/>
<Ellipse Margin="0" Grid.RowSpan="2" Grid.Column="1" Grid.Row="1" Fill="{DynamicResource HighlightBrush}"/>
<Ellipse Margin="0" Grid.RowSpan="3" Grid.ColumnSpan="3" Grid.Row="1" Fill="{DynamicResource LightBrush}"/>
</Grid>
</UserControl>

New Topic/Question
Reply




MultiQuote



|