Xaml 如何使用单个样式设置UWP中嵌套控件的样式?

Xaml 如何使用单个样式设置UWP中嵌套控件的样式?,xaml,uwp,styles,Xaml,Uwp,Styles,在一个UWP项目中,我在一个边框内,一个按钮内得到了一个文本块。像这样: <Button Style="{StaticResource MyBtnStyle}"> <Border> <TextBlock/> </Border> </Button> 我想设置一种样式,一次自定义所有控件。大概是这样的: <Style x:Name="MyBtnStyle" Targe

在一个UWP项目中,我在一个边框内,一个按钮内得到了一个文本块。像这样:

<Button Style="{StaticResource MyBtnStyle}">
   <Border>
     <TextBlock/>
   </Border>
</Button>

我想设置一种样式,一次自定义所有控件。大概是这样的:

<Style x:Name="MyBtnStyle" TargetType="Button">
   <Setter Property="Background" Value="Gray"/>
   <Style TargetType="Border>
   <Setter Property="BorderThickness" Value="0,0,0,5"/>
       <Style TargetType="TextBlock">
       <Setter Property="FontSize" Value="20"/>
       </Style>
   </Style>  
</Style>


不,你不能那样做。可以为按钮创建样式并更改其模板属性。然后,您可以自定义边框和文本块,以替换默认按钮样式中的默认ContentPresenter

另一种方法是为每个零件创建三种sperate样式,并分别使用它们