My button template

I use especiall button template. Here is an article for one button.

But using it we need to create template for every button.
For play – play template.
For stop – stop template.
For pause – pause template.

But all template will content common part – button and different – button content. So I want one template for button template and different for buttons content.

<!--Button template-->
    <Style x:Key="smartButton" TargetType="{x:Type Button}">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Template">
                <ControlTemplate TargetType="{x:Type Button}">
                            <RowDefinition Height="10*" />
                            <RowDefinition Height="10*" />
                            <RowDefinition Height="10*" />
                            <ColumnDefinition Width="10*" />
                            <ColumnDefinition Width="10*" />
                            <ColumnDefinition Width="10*" />
                        <Rectangle x:Name="buttonRect" Grid.ColumnSpan="3" Grid.RowSpan="3" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" RadiusX="10" RadiusY="10" StrokeThickness="1" Stroke="{StaticResource fillBrush}"/>
                        <ContentPresenter Grid.Column="1" Grid.Row="1" x:Name="buttonContent" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Center" RecognizesAccessKey="True"/>
                        <Trigger Property="Button.IsMouseOver" Value="True">
                            <Setter TargetName="buttonRect" Property="Fill" Value="{StaticResource selectBrush}"/>
                        <Trigger Property="Button.IsPressed" Value="True">
                            <Setter Property="RenderTransform" TargetName="buttonContent">
                                    <TranslateTransform X="1" Y="1"/>
                            <!--<Setter TargetName="buttonRect" Property="Fill" Value="Transparent"/>-->
I've got error that one image can't be used in the different buttons. The solution was set

X:shared = false

Last edited Sep 17, 2010 at 11:17 PM by Denis_Yakimenko, version 12


No comments yet.