I want to set consistent margins throughout all controls within an entire view. I currently use XAML:
<Window.Resources>
<Thickness x:Key="ConsistentMargins">0,10,0,0</Thickness>
</Window.Resources>
<!-- ... -->
<!-- ... -->
<!-- ... -->
<MyControl1 Margin="{StaticResource ConsistentMargins}">
<MyControl2 Margin="{StaticResource ConsistentMargins}">
<MyControl3 Margin="{StaticResource ConsistentMargins}">
Is there a way to set a default layout style for controls to avoid the above repeated code shown above?
You can create your own style with
TargetTypeand this style will be assigned to all object of type which you specified inTargetType. But in this case your created style will be applied only for speciefied type of object, but not for derived type.E.g. you can create style for all buttons like this:
I think that this makes sense that style is not applied from base class, because I want say “My all buttons looks like…”, but I want not say “Everything looks like…”.