[转帖]翔麟专集——WPF界面设计技巧(2)—自定义漂亮的按钮样式
<p>本贴摘自<a class="dropmenu" id="fjump" href="http://wpf.5d6d.com/bbs.php" initialized="initialized" unselectable="unselectable" outfunc="null" w="192" h="16" y="138" x="280"><font color="#000000">WPF - 飘雪论坛|WPF论坛NO.1</font></a> 作者:<a href="http://wpf.5d6d.com/space.php?uid=1" target="_blank" style="FONT-WEIGHT: 800; MARGIN-LEFT: 20px;"><font color="#000000">CStrings</font></a></p><p></p><hr/><p></p><p style="FONT-SIZE: 10pt; MARGIN: 0in;">上次做了个<a href="http://www.cnblogs.com/SkyD/archive/2008/07/13/1242044.html"><font color="#56b6e9">很酷的不规则窗体</font></a>,这次我们来弄点好看的按钮出来,此次将采用纯代码来设计按钮样式,不需要<br/> Microsoft Expression Design 辅助了。</p><p style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: SimSun;"> </p><p style="FONT-SIZE: 10pt; MARGIN: 0in;">首先打开<br/> Microsoft Visual Studio 2008<br/> ,新建一个<span class="t_tag" href="tag.php?name=WPF">WPF</span>项目,在上面随便放几个按钮:</p><p style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: SimSun;"> </p><p style="MARGIN: 0in;"><img alt="" src="http://images.cnblogs.com/cnblogs_com/skyd/WPF_Button.png" border="0"/></p><p style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: SimSun;"> </p><p style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: SimSun;">然后给各个按钮设置不同的背景颜色:</p><p style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: SimSun;"> </p><p style="MARGIN: 0in;"><img alt="" src="http://images.cnblogs.com/cnblogs_com/skyd/WPF_Button_12.png" border="0"/></p><p style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: SimSun;"> </p><p style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: SimSun;">设置好之后就是这样啦:</p><p style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: SimSun;"> </p><p style="MARGIN: 0in;"><img alt="" src="http://images.cnblogs.com/cnblogs_com/skyd/WPF_Button_2.png" border="0"/></p><p style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: SimSun;"> </p><p style="FONT-SIZE: 10pt; MARGIN: 0in;">然后我们就开始在 App.xaml 文件中<span class="t_tag" href="tag.php?name=%B6%A8%D2%E5">定义按钮样式了:</span></p><p style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: SimSun;"> </p><p style="MARGIN: 0in;"><img alt="" src="http://images.cnblogs.com/cnblogs_com/skyd/WPF_Button_6.png" border="0"/></p> 本贴摘自WPF - 飘雪论坛|WPF论坛NO.1 作者:CStrings定义的样式代码如下:<Application x:Class="WPFButton.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
<Application.Resources>
<!--定义按钮样式-->
<Style TargetType="Button">
<Setter Property="Foreground" Value="Black"/>
<!--修改模板属性-->
<Setter Property="Template">
<Setter.Value>
<!--控件模板-->
<ControlTemplate TargetType="Button">
<!--背景色-->
<Border x:Name="back" Opacity="0.8" CornerRadius="3">
<Border.BitmapEffect>
<OuterGlowBitmapEffect Opacity="0.7" GlowSize="0" GlowColor="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Button.Background).(SolidColorBrush.Color)}" />
</Border.BitmapEffect>
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1.5">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Button.Background).(SolidColorBrush.Color)}" Offset="0"/>
<GradientStop Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Button.Background).(SolidColorBrush.Color)}" Offset="0.4"/>
<GradientStop Color="#FFF" Offset="1"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
<!--前景色及边框-->
<Border x:Name="fore" BorderThickness="1" CornerRadius="3" BorderBrush="#5555">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#6FFF" Offset="0.5"/>
<GradientStop Color="#1111" Offset="0.51"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
<!--按钮内容-->
<ContentPresenter x:Name="content" HorizontalAlignment="Center" VerticalAlignment="Center" Content="{TemplateBindingContent}">
<ContentPresenter.BitmapEffect>
<DropShadowBitmapEffect Color="#000" Direction="-90" ShadowDepth="2" Softness="0.1" Opacity="0.3" />
</ContentPresenter.BitmapEffect>
</ContentPresenter>
</Border>
</Border>
<!--触发器-->
<ControlTemplate.Triggers>
<!--鼠标移入移出-->
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation To="6" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
<ColorAnimation To="#AFFF" BeginTime="0:0:0.2" Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
<ColorAnimation To="#3FFF" BeginTime="0:0:0.2" Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
<!--按钮按下弹起-->
<Trigger Property="IsPressed" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation To="3" Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
<ColorAnimation To="#3AAA" Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
<ColorAnimation To="#2111" Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
<!--按钮失效-->
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="#B444"/>
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation To="0" Duration="0:0:0.3" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
<DoubleAnimation To="1" Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Opacity)" />
<DoubleAnimation To="-135" Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Direction)" />
<ColorAnimation To="#FFF" Duration="0:0:0.3" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Color)" />
<ColorAnimation To="#D555" Duration="0:0:0.3" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" />
<ColorAnimation To="#CEEE" Duration="0:0:0.3" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
<ColorAnimation To="#CDDD" Duration="0:0:0.3" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Opacity)" />
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Direction)" />
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Color)" />
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" />
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
</Application>
看了先不要头大,我们先看看最终效果,然后回过头来再解释代码:
http://images.cnblogs.com/cnblogs_com/skyd/WPF_Button_3.png
这是常规样式
http://images.cnblogs.com/cnblogs_com/skyd/WPF_Button_4.png
这个是鼠标移到上面时的样式
http://images.cnblogs.com/cnblogs_com/skyd/WPF_Button_5.png
这个是鼠标点击时的样式
http://images.cnblogs.com/cnblogs_com/skyd/WPF_Button_10.png
还有就是按钮失效时的样式
效果还算不错吧,下面来讲解代码喽,头晕的同学可以现在就收拾东西回家了哈。
http://images.cnblogs.com/cnblogs_com/skyd/WPF_Button_7.png
我们先来看这个命名为“back”的 Border 元素,它用它的 Background 属性充当了整个按钮的背景色。
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Border.Background>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1.5">
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<GradientBrush.GradientStops>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<GradientStopCollection>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<GradientStop Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Button.Background).(SolidColorBrush.Color)}" Offset="0"/>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<GradientStop Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Button.Background).(SolidColorBrush.Color)}" Offset="0.4"/>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<GradientStop Color="#FFF" Offset="1"/>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</GradientStopCollection>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</GradientBrush.GradientStops>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</LinearGradientBrush>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Border.Background>
其背景所用的是一个渐变笔刷,起始值和中间值都是引用的按钮本身的背景色,就是我们之前设置过的颜色啦,终止值是白色,这样通过位置调整,我们可以在按钮最下部产生一些向白色的过度色彩效果。
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Border.BitmapEffect>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<OuterGlowBitmapEffect Opacity="0.7" GlowSize="0" GlowColor="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Button.Background).(SolidColorBrush.Color)}" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Border.BitmapEffect>
它的 BitmapEffect 属性我们设置了一个大小为 0 的外发光效果,平常是看不见这效果的,在这里预先设置好,是为了在鼠标移入、按下时实现动画使用。
http://images.cnblogs.com/cnblogs_com/skyd/WPF_Button_8.png
再来看看这个命名为“fore”的 Border 元素,它实现的是按钮的边框和高亮反光效果,我为它设置了一个半透明的黑色1像素边框,使得这个边框的色彩可以和背景色混合起来。
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Border.Background>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<GradientBrush.GradientStops>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<GradientStopCollection>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<GradientStop Color="#6FFF" Offset="0.5"/>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<GradientStop Color="#1111" Offset="0.51"/>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</GradientStopCollection>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</GradientBrush.GradientStops>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</LinearGradientBrush>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Border.Background>
它的背景同样采用的渐变笔刷,起始值和终止值的位置几乎贴在一起,从而形成比较鲜明的反光度对比。
http://images.cnblogs.com/cnblogs_com/skyd/WPF_Button_9.png
ContentPresenter 元素用于呈现按钮原本的内容,对于按钮来说就是按钮上的文字了,当然也可能会存在图片或其它东西。
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ContentPresenter.BitmapEffect>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<DropShadowBitmapEffect Color="#000" Direction="-90" ShadowDepth="2" Softness="0.1" Opacity="0.3" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</ContentPresenter.BitmapEffect>
我为之加了一个不太明显的阴影滤镜以增强显示效果。
http://images.cnblogs.com/cnblogs_com/skyd/WPF_Button_11.png
剩下的就是些可爱又该死的 Trigger ,我们通过这些触发器来改变按钮在不同状态时的外观。
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<!--鼠标移入移出-->
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Trigger Property="IsMouseOver" Value="True">
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Trigger.EnterActions>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<BeginStoryboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Storyboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<DoubleAnimation To="6" Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation To="#AFFF" BeginTime="0:0:0.2" Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation To="#3FFF" BeginTime="0:0:0.2" Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Storyboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</BeginStoryboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Trigger.EnterActions>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Trigger.ExitActions>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<BeginStoryboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Storyboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Storyboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</BeginStoryboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Trigger.ExitActions>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Trigger>
在鼠标移入按钮时,我依次创建了改变外发光效果大小、改变上部反光区域颜色、改变下部反光区域颜色的动画,这里的要点就在于“Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)"”属性设置语句,琢磨一下你就能看出这是对属性路径的描述,只不过它们写起来和看起来都很让人生气。
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<!--按钮按下弹起-->
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Trigger Property="IsPressed" Value="True">
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Trigger.EnterActions>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<BeginStoryboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Storyboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<DoubleAnimation To="3" Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation To="#3AAA" Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation To="#2111" Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Storyboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</BeginStoryboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Trigger.EnterActions>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Trigger.ExitActions>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<BeginStoryboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Storyboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Storyboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</BeginStoryboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Trigger.ExitActions>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Trigger>
按下和弹起按钮时,我们做了相似的动画改变,与前面相比只是数值略微不同。
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<!--按钮失效-->
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Trigger Property="IsEnabled" Value="False">
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Setter Property="Foreground" Value="#B444"/>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Trigger.EnterActions>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<BeginStoryboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Storyboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<DoubleAnimation To="0" Duration="0:0:0.3" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<DoubleAnimation To="1" Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Opacity)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<DoubleAnimation To="-135" Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Direction)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation To="#FFF" Duration="0:0:0.3" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation To="#D555" Duration="0:0:0.3" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation To="#CEEE" Duration="0:0:0.3" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation To="#CDDD" Duration="0:0:0.3" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Storyboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</BeginStoryboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Trigger.EnterActions>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Trigger.ExitActions>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<BeginStoryboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<Storyboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="back" Storyboard.TargetProperty="(Border.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Opacity)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<DoubleAnimation Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Direction)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="content" Storyboard.TargetProperty="(ContentPresenter.BitmapEffect).(DropShadowBitmapEffect.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
<ColorAnimation Duration="0:0:0.1" Storyboard.TargetName="fore" Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops).(GradientStop.Color)" />
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Storyboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</BeginStoryboard>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Trigger.ExitActions>
http://www.cnblogs.com/Images/OutliningIndicators/None.gif
</Trigger>
当按钮失效时,我要改变很多东西,首先将文字颜色设为灰色,然后依次创建了改变外发光效果大小、改变内容阴影效果不透明度、改变内容阴影效果角度、改变内容阴影效果颜色、改变按钮边框颜色、改变上部反光区域颜色、改变下部反光区域颜色的动画。
这里将先前对内容应用的阴影效果彻底改变,使之产生凹陷的效果。
好了,到这里就下课啦,文章有点冗长了,但应该对新手很有帮助,老鸟估计现在已经梦游仙境了吧。
不错 学习了 谢谢<strong>翔麟,</strong>学习学习 <p>看这代码.我就有点晕了.</p><p></p><p>游天居士到此一游</p> <p>visual baisic 2005能实现么?</p> 谢谢分享 学习了 xml阅读起来很费力……
页:
[1]