Using a ControlTemplate within a Style : ControlTemplate « UI Controls « Silverlight






Using a ControlTemplate within a Style

Using a ControlTemplate within a Style
    
<UserControl x:Class='SilverlightApplication3.MainPage'
    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' 
    mc:Ignorable='d' 
    d:DesignWidth='640' 
    d:DesignHeight='480'>
   
        <StackPanel x:Name="LayoutRoot" Background="White" Margin="10" Width="170">
            <StackPanel.Resources>
                <Style x:Key="buttonStyle" TargetType="Button">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Ellipse Fill="#FF2103BA" Stroke="Black" StrokeThickness="2"  Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" />
                            </ControlTemplate> 
                        </Setter.Value>
                    </Setter>
                </Style>
            </StackPanel.Resources>

            <Button x:Name="myButton1" Height="30" Width="30" Style="{StaticResource buttonStyle}" />
            <Button x:Name="myButton2" Height="70" Width="70" Style="{StaticResource buttonStyle}" />
        </StackPanel>
</UserControl>

   
    
    
    
  








Related examples in the same category

1.Simple ControlTemplate
2.Using a TemplateBinding to use the target elements propertiesUsing a TemplateBinding to use the target elements properties
3.Basic Template