uwp自带的button本身不支持圆角属性,所以要通过自定义控件实现。
通过设置Button的Background=“{x:Null}”设置为Null使背景为空,再设置Button.Content中的内容,采用如下代码方式:
前端代码:
1 <UserControl 2 x:Class="Test.UWP.ExtendControls.UWPButton" 3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 5 xmlns:local="using:Mixin.UWP.ExtendControls" 6 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 7 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 8 mc:Ignorable="d"> 9 <Grid Background="{x:Null}"> 10 <Grid Grid.Row="0"> 11 <StackPanel Name="stack_Panel"> 12 <Button Click="btnDailog_Click" Background="{x:Null}" HorizontalAlignment="Stretch" Style="{StaticResource UWPDialogBtnStyle}"> 13 <Button.Content> 14 <Grid > 15 <Grid Grid.Row="0" > 16 <Rectangle Fill="White" RadiusX="6" RadiusY="6"></Rectangle> 17 <StackPanel HorizontalAlignment="Center" Margin="8,4,8,4"> 18 <TextBlock x:Name="btnText" >我是自定义按钮</TextBlock> 19 </StackPanel> 20 </Grid> 21 </Grid> 22 </Button.Content> 23 </Button> 24 25 </StackPanel> 26 27 </Grid> 28 </Grid> 29 30 </UserControl>