Is there any way in XAML to set a style that will apply to all controls? For example, below I would like to put a margin in all my controls. I can add a style for each type by changing TargetType to Button, CheckBox, etc. Instead, I would like to configure it as shown below, where I set the style for all types that inherit from 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>
source share