XAML 中有没有办法设置适用于所有控件的样式?例如下面我想在我的所有控件上设置一个边距。我可以通过将 TargetType 更改为 Button、CheckBox 等来为每种类型添加样式。相反,我想像下面那样设置它,在其中设置从 Control 继承的所有类型的样式:
<UserControl x:Class="MyPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Height="300" Width="300">
<UserControl.Resources>
<Style TargetType="Control">
<Setter Property="Margin" Value="3"/>
</Style>
</UserControl.Resources>
<StackPanel>
<Button>My Button</Button>
<CheckBox>My Checkbox</CheckBox>
</StackPanel>
</UserControl>