WPF Silverlight Button样式

来源:互联网 发布:浙江淘宝总部地址 编辑:程序博客网 时间:2024/06/05 06:06

   <Button Width="75" Height="25" Content="查询" Foreground="White" Background="SlateGray">
            <Button.Template>
                <ControlTemplate TargetType="Button">
                    <Grid>

                        <Border Name="BackgroundAnimation" CornerRadius="2" Background="{TemplateBinding Background}"/>

                        <!--<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>-->

                        <!--应用此处可控制文字前景色 与下面Pressed中的 Storyboard.TargetName="ForegroundAnimation" 共同作用 与ContentPresenter部分相斥-->
                        <ContentControl Name="ForegroundAnimation" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Foreground="{TemplateBinding Foreground}"/>

                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ColorAnimation Duration="0" To="Green" Storyboard.TargetName="BackgroundAnimation" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"/>
                                    </Storyboard>
                                </VisualState>
                               
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ColorAnimation Duration="0" To="Red" Storyboard.TargetName="BackgroundAnimation" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"/>
                                        <ColorAnimation Duration="0" To="Yellow" Storyboard.TargetName="ForegroundAnimation" Storyboard.TargetProperty="(ContentControl.Foreground).(SolidColorBrush.Color)"/>

                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundAnimation"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>

                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundAnimation"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unfocused"/>
                            </VisualStateGroup>

                        </VisualStateManager.VisualStateGroups>

                    </Grid>

 

                </ControlTemplate>
            </Button.Template>
        </Button>

0 0
原创粉丝点击