Template Binding : Template « UI Controls « Silverlight






Template Binding

Template Binding
    

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

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.Resources>
            <Style x:Key="NewButton" TargetType="Button">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">

                            <Grid>
                                <Ellipse Width="{TemplateBinding Width}" 
                                         Height="{TemplateBinding Height}" 
                                         Fill="Green" />

                                <ContentPresenter Content="{TemplateBinding Content}"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="Center" />
                            </Grid>

                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

        </Grid.Resources>

        <Button Style="{StaticResource NewButton}" Content="The Content" />
    </Grid>


</UserControl>

   
    
    
    
  








Related examples in the same category

1.Template PartsTemplate Parts
2.Template States
3.Changing the look of a Button through a TemplateChanging the look of a Button through a Template