王韧竹 的专栏

Win8 Ms Design开发者联盟 195314253

透明BUTTON 模板 WPF

  <ControlTemplate x:Key="NavTemp" TargetType="{x:Type Button}">
        <Grid Width="{TemplateBinding Width}" Background="{TemplateBinding Background}"
      Height="80" ClipToBounds="True">
            <Label Content="{TemplateBinding Content}" Margin="10,20,0,0"/>
        </Grid>
    </ControlTemplate>

 

 

="{StaticResource ShopBtnBrush}"  这个东西就是图片 随意替换

 

<ControlTemplate x:Key="HomeBtnTemplate" TargetType="{x:Type Button}">
        <Grid Width="{TemplateBinding Width}" Background="{TemplateBinding Background}"
      Height="{TemplateBinding Height}" ClipToBounds="True">
            <Rectangle x:Name="glassCube" HorizontalAlignment="Stretch"
        VerticalAlignment="Stretch" Opacity="1"
        Fill="{StaticResource ShopBtnBrush}"  RenderTransformOrigin="0.5,0.5"
                        RadiusX="10" RadiusY="10">
                <Rectangle.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform />
                    </TransformGroup>
                </Rectangle.RenderTransform>
            </Rectangle>
        </Grid>

        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Rectangle.Opacity" Value="1"       TargetName="glassCube" />
            </Trigger>
            <Trigger Property="IsFocused" Value="true">
                <Setter Property="Rectangle.Opacity" Value="1"   TargetName="glassCube" />
            </Trigger>
            <EventTrigger RoutedEvent="Mouse.MouseEnter">
                <EventTrigger.Actions>
                    <BeginStoryboard Name="mouseEnterBeginStoryboard">
                        <Storyboard AutoReverse="True">
                            <DoubleAnimation Storyboard.TargetName="glassCube"
          Storyboard.TargetProperty=
          "(Rectangle.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
          By="0.03" Duration="0:0:0.2" />
                            <DoubleAnimation
        Storyboard.TargetName="glassCube"
          Storyboard.TargetProperty=
          "(Rectangle.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
          By="0.03" Duration="0:0:0.2" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger.Actions>
            </EventTrigger>
            <EventTrigger RoutedEvent="Mouse.MouseLeave">
                <EventTrigger.Actions>
                </EventTrigger.Actions>
            </EventTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

 

阅读更多
文章标签: button wpf setter
个人分类: WPF XAML
上一篇BUTTON WPF 样式
下一篇GC 回收WPF 内存 C#通用
想对作者说点什么? 我来说一句

WPF中做出透明按钮

2013年11月14日 63KB 下载

没有更多推荐了,返回首页

关闭
关闭