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">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="10*" />
                            <RowDefinition Height="10*" />
                            <RowDefinition Height="10*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="10*" />
                            <ColumnDefinition Width="10*" />
                            <ColumnDefinition Width="10*" />
                        </Grid.ColumnDefinitions>
                        <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"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Button.IsMouseOver" Value="True">
                            <Setter TargetName="buttonRect" Property="Fill" Value="{StaticResource selectBrush}"/>
                        </Trigger>
                        <Trigger Property="Button.IsPressed" Value="True">
                            <Setter Property="RenderTransform" TargetName="buttonContent">
                                <Setter.Value>
                                    <TranslateTransform X="1" Y="1"/>
                                </Setter.Value>
                            </Setter>
                            <!--<Setter TargetName="buttonRect" Property="Fill" Value="Transparent"/>-->
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
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 10:17 PM by Denis_Yakimenko, version 12

Comments

No comments yet.