程序员

XAML中Button重绘为圆形的方法技巧

作者:admin 2021-06-15 我要评论

在用XAML布局的时候,有时候为了使界面Metro化,有些Button要使用圆形代替默认的长方形。以下的Button样式可以解决这个问题,可以根据自己的需要再加以修改。当...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)
在用XAML布局的时候,有时候为了使界面Metro化,有些Button要使用圆形代替默认的长方形。以下的Button样式可以解决这个问题,可以根据自己的需要再加以修改。当然如果你熟悉Bland的话可以直接使用它来绘制你需要的样式,但是贴代码是否更快一点呢?

复制代码
代码如下:

<Style x:Key="btnNext" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="rectangle">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Thickness>-3</Thickness>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Normal"/>
<VisualState x:Name="Disabled"/>
<VisualState x:Name="MouseOver"/>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="rectangle" RadiusY="25" RadiusX="25" Stroke="Blue" StrokeThickness="4">
</Rectangle>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Margin" Value="5"/>
<Setter Property="Width" Value="50"/>
<Setter Property="Height" Value="50"/>
<Setter Property="FontSize" Value="120"/>
<Setter Property="Foreground" Value="White"/>
</Style>


原文链接:https://m.jb51.net/web/80640.html

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • XAML中Button重绘为圆形的方法技巧

    XAML中Button重绘为圆形的方法技巧

  • 如何在HTML中加载Flash(2种实现方法)

    如何在HTML中加载Flash(2种实现方法)

  • map标签的参数详细介绍及使用示例

    map标签的参数详细介绍及使用示例

  • IMG中UserMap的使用示例

    IMG中UserMap的使用示例

腾讯云代理商
精彩导读
海外云服务器
热门资讯
腾讯云代理商