WPF Button 透明效果

简介:

Button 透明效果

<Window x:Class= "ControlTest2.ButtonGlassTest"
     xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"
     Title= "ButtonGlassTest"  Height= "480"  Width= "640" >
     <Window.Resources>
         <ControlTemplate x:Key= "GlassButton"  TargetType= "{x:Type Button}" >
             <ControlTemplate.Resources>
                 <Storyboard x:Key= "Timeline1" >
                     <DoubleAnimationUsingKeyFrames BeginTime= "00:00:00"  Storyboard.TargetName= "glow"  Storyboard.TargetProperty= "(UIElement.Opacity)" >
                         <SplineDoubleKeyFrame KeyTime= "00:00:00.3000000"  Value= "1" />
                     </DoubleAnimationUsingKeyFrames>
                 </Storyboard>
                 <Storyboard x:Key= "Timeline2" >
                     <DoubleAnimationUsingKeyFrames BeginTime= "00:00:00"  Storyboard.TargetName= "glow"  Storyboard.TargetProperty= "(UIElement.Opacity)" >
                         <SplineDoubleKeyFrame KeyTime= "00:00:00.3000000"  Value= "0" />
                     </DoubleAnimationUsingKeyFrames>
                 </Storyboard>
             </ControlTemplate.Resources>
             <Border BorderBrush= "#FFFFFFFF"  BorderThickness= "1,1,1,1"  CornerRadius= "4,4,4,4" >
                 <Border x:Name= "border"  Background= "#7F000000"  BorderBrush= "#FF000000"  BorderThickness= "1,1,1,1"  CornerRadius= "4,4,4,4" >
                     <Grid>
                         <Grid.RowDefinitions>
                             <RowDefinition Height= "0.507*" />
                             <RowDefinition Height= "0.493*" />
                         </Grid.RowDefinitions>
                         <Border Opacity= "0"  HorizontalAlignment= "Stretch"  x:Name= "glow"  Width= "Auto"  Grid.RowSpan= "2"  CornerRadius= "4,4,4,4" >
                             <Border.Background>
                                 <RadialGradientBrush>
                                     <RadialGradientBrush.RelativeTransform>
                                         <TransformGroup>
                                             <ScaleTransform ScaleX= "1.702"  ScaleY= "2.243" />
                                             <SkewTransform AngleX= "0"  AngleY= "0" />
                                             <RotateTransform Angle= "0" />
                                             <TranslateTransform X= "-0.368"  Y= "-0.152" />
                                         </TransformGroup>
                                     </RadialGradientBrush.RelativeTransform>
                                     <GradientStop Color= "#B28DBDFF"  Offset= "0" />
                                     <GradientStop Color= "#008DBDFF"  Offset= "1" />
                                 </RadialGradientBrush>
                             </Border.Background>
                         </Border>
                         <ContentPresenter HorizontalAlignment= "Center"  VerticalAlignment= "Center"  Width= "Auto"  Grid.RowSpan= "2" />
                         <Border HorizontalAlignment= "Stretch"  Margin= "0,0,0,0"  x:Name= "shine"  Width= "Auto"  CornerRadius= "4,4,0,0" >
                             <Border.Background>
                                 <LinearGradientBrush EndPoint= "0.494,0.889"  StartPoint= "0.494,0.028" >
                                     <GradientStop Color= "#99FFFFFF"  Offset= "0" />
                                     <GradientStop Color= "#33FFFFFF"  Offset= "1" />
                                 </LinearGradientBrush>
                             </Border.Background>
                         </Border>
                     </Grid>
                 </Border>
             </Border>
             <ControlTemplate.Triggers>
                 <Trigger Property= "IsPressed"  Value= "True" >
                     <Setter Property= "Opacity"  TargetName= "shine"  Value= "0.4" />
                     <Setter Property= "Background"  TargetName= "border"  Value= "#CC000000" />
                     <Setter Property= "Visibility"  TargetName= "glow"  Value= "Hidden" />
                 </Trigger>
                 <Trigger Property= "IsMouseOver"  Value= "True" >
                     <Trigger.EnterActions>
                         <BeginStoryboard Storyboard= "{StaticResource Timeline1}" />
                     </Trigger.EnterActions>
                     <Trigger.ExitActions>
                         <BeginStoryboard x:Name= "Timeline2_BeginStoryboard"  Storyboard= "{StaticResource Timeline2}" />
                     </Trigger.ExitActions>
                 </Trigger>
             </ControlTemplate.Triggers>
         </ControlTemplate>
     </Window.Resources>
     <Grid>
         <Grid.Background>
             <LinearGradientBrush EndPoint= "0.486,0.986"  StartPoint= "0.486,0" >
                 <GradientStop Color= "#FF000000"  Offset= "0" />
                 <GradientStop Color= "#FFD0D0D0"  Offset= "1" />
                 <GradientStop Color= "#FF8D8D8D"  Offset= "0.558" />
                 <GradientStop Color= "#FF8D8D8D"  Offset= "0.76" />
                 <GradientStop Color= "#FF747474"  Offset= "0.615" />
             </LinearGradientBrush>
         </Grid.Background>
         <Button HorizontalAlignment= "Left"  Margin= "31,0,0,182"  VerticalAlignment= "Bottom"  Width= "176"  Height= "34"  Content= "Button"  Foreground= "#FFFFFFFF"
                 Template= "{DynamicResource GlassButton}" />
         <Image  Margin= "221,89,27.001,73"  Source= "Aero_Grass.jpg"  Stretch= "Fill" >
             <Image.OpacityMask>
                 <RadialGradientBrush>
                     <GradientStop Color= "#FF000000"  Offset= "0" />
                     <GradientStop Color= "#00FFFFFF"  Offset= "1" />
                 </RadialGradientBrush>
             </Image.OpacityMask>
         </Image>
         <Button HorizontalAlignment= "Right"  Margin= "0,0,120,158"  VerticalAlignment= "Bottom"  Width= "179"  Height= "34"  Content= "My New Glass Button"
                 Foreground= "#FFFFFFFF"  Template= "{DynamicResource GlassButton}" />
         <Button Width= "179"  Foreground= "#FFFFFFFF"  Template= "{DynamicResource GlassButton}"  HorizontalAlignment= "Right"  Margin= "0,192,120,218" >
             <StackPanel HorizontalAlignment= "Left"  Width= "Auto"  Height= "Auto"  Orientation= "Horizontal" >
                 <Image Width= "20"  Height= "20"  Source= "Aero_Grass.jpg"  Stretch= "Fill" />
                 <TextBlock Margin= "5,0,50,0"  VerticalAlignment= "Center"  FontSize= "12"  Text= "Internet Explorer"  TextWrapping= "Wrap" />
             </StackPanel>
         </Button>
     </Grid>
</Window>

 如图:

 

 


本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/archive/2011/11/08/2241135.html,如需转载请自行联系原作者


目录
相关文章
|
9月前
|
C#
WPF技术之Slider控件
Slider控件是WPF中常用的用于选择范围值的控件之一。它可以通过拖动滑块来选择一个在指定范围内的数值。
221 0
WPF技术之Slider控件
|
9月前
|
C# Windows
WPF技术之Button控件
WPF(Windows Presentation Foundation)是用于创建 Windows 客户端应用程序的一种技术。在 WPF 中,按钮是常用的控件之一,用于触发某种行为或操作。
206 0
WPF技术之Button控件
|
C#
WPF 自定义模板 Button闪亮效果
原文:WPF 自定义模板 Button闪亮效果 Button的选中Effect,我们看下下面的效果:   让我们再放大一点: 怎么设置上面样式呢?直接设置Button的Effect,有点问题,因为Effect不是四周环绕的。
567 0
|
C#
wpf 触摸屏 button 背景为null的 问题
原文:wpf 触摸屏 button 背景为null的 问题 ...
799 0
|
C#
【WPF】wpf用MultiBinding解决Converter需要动态传参的问题,以Button为例
原文:【WPF】wpf用MultiBinding解决Converter需要动态传参的问题,以Button为例       用Binding并通过Converter转换的时候,可能偶尔会遇到传参的问题,一般通过设置xaml中的BindingParameter属性来给Converter传递参数。
1901 0
|
C#
WPF 自定义模板 Button闪亮效果
Button的选中Effect,我们看下下面的效果:   让我们再放大一点: 怎么设置上面样式呢?直接设置Button的Effect,有点问题,因为Effect不是四周环绕的。那我们也只能重新定义Template了。
693 0
|
1月前
|
C# 开发者 Windows
基于Material Design风格开源、易用、强大的WPF UI控件库
基于Material Design风格开源、易用、强大的WPF UI控件库
|
5月前
|
C#
浅谈WPF之装饰器实现控件锚点
使用过visio的都知道,在绘制流程图时,当选择或鼠标移动到控件时,都会在控件的四周出现锚点,以便于修改大小,移动位置,或连接线等,那此功能是如何实现的呢?在WPF开发中,想要在控件四周实现锚点,可以通过装饰器来实现,今天通过一个简单的小例子,简述如何在WPF开发中,应用装饰器,仅供学习分享使用,如有不足之处,还请指正。
66 1