I’ve set some default styles for basic elements in WPF that act as default styles for the application, this allows controls such as buttons to all carry a similar look and feel without having to adjust manually when defined, this also means that it only needs to be changed once.
A snippet of my resource dictionary looks as follows:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="Button">
<Setter Property="Margin" Value="4"/>
<Setter Property="MinWidth" Value="75"/>
<Setter Property="Padding" Value="10,2"/>
</Style>
</ResourceDictionary>
Notice here that I’m setting Margin to 4 for all sides. This is great as it provides a gap between buttons without the interface needing to explicitly define it. I want to know how I can for a single button, remove the gap on one side without needing to define “4” for the other sides to allow it to butt up against the side of its parent.
I don’t want to do the following as it deviates from the style (i.e. if I change 4 to 5 in my style I also need to do it here):
<DockPanel>
<Button DockPanel.Dock="Left" Content="My Button" Margin="0,4,4,4" />
</DockPanel>
I just want to set MarginLeft somehow and leave the others as the default style I defined.
NOTE: I do have a workaround which is to simply use a named style of “buttonLeft” which is defined in the resource dictionary with no left margin.
i think your workaround is fine 🙂 if you want a MarginLeft Property you should create your own button and add this Property.