tags:

views:

38

answers:

0

Can I simplify my code?

        <Style x:Key="GrayButtonStyle" TargetType="ButtonBase">
        <Setter Property="Margin" Value="5"></Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ButtonBase">
                    <Border x:Name="border" BorderThickness="2" CornerRadius="15" BorderBrush="#FF211c19" RenderTransformOrigin="0.5,0.5">
                        <Border.RenderTransform>
                            <CompositeTransform/>
                        </Border.RenderTransform>
                        <Border.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FF959b9c" Offset="0"/>
                                <GradientStop Color="#FF0E0505" Offset="1"/>
                            </LinearGradientBrush>
                        </Border.Background>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Disabled"/>
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver"/>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="2" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="border" />
                                        <ColorAnimation Duration="0:0:0.2" To="#FF392929" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="border"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <TextBlock TextWrapping="Wrap" Text="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,5"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

I want make the ToggleButton the same. The only difference is VisualState x:Name="Pressed" is Checked. Is this possible with templates?

      <Style x:Key="GrayToggleButtonStyle" TargetType="ToggleButton"  BasedOn="{StaticResource GrayButtonStyle}">

I'm trying BasedOn Property yet I have problem with the template.