头闻号

东莞市同创塑胶工艺礼品有限公司

饰品加工|礼品、工艺品、饰品设计|汽车装潢内饰用品|鞋材、鞋件加工|洗涤标、商标

首页 > 新闻中心 > 科技常识:XAML中Button重绘为圆形的方法技巧
科技常识:XAML中Button重绘为圆形的方法技巧
发布时间:2024-09-22 04:08:34        浏览次数:6        返回列表

今天小编跟大家讲解下有关XAML中Button重绘为圆形的方法技巧 ,相信小伙伴们对这个话题应该有所关注吧,小编也收集到了有关XAML中Button重绘为圆形的方法技巧 的相关资料,希望小伙伴们看了有所帮助。

在用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>

来源:爱蒂网