I have created a UserControl that is working just fine. If I set the margin in code all goes well:
<cbtn:BillLister Margin="10,5,10,5" />
However, when i try to set it for everyone of those that are in the wrappannel they are in, this doesn't work:
<WrapPanel.Resources>
<Style TargetType="cbtn:BillLister">
<Style.Setters>
<Setter Property="Margin" Value="150,35,50,35" />
<Setter Property="Background" Value="Black"/>
</Style.Setters>
</Style>
The Background property is working however, so i know that it is targeting the correct UserControls.
I did find this: How to give my custom control an overridable default margin? I tried what he did in there, and still no change.
public partial class BillLister : UserControl
{
public BillLister()
{
InitializeComponent();
Labelcount.Content = "0";
}
static BillLister()
{
MarginProperty.OverrideMetadata(typeof(BillLister), new FrameworkPropertyMetadata(new Thickness(30, 130, 30, 30)));
}
...
Does anyone have any idea what might be going on here? I would hate to have to set the margin on each one manually.
Update to clarify: When trying the second version i don't use the inline margin from the first one. Also, the margin fromthe second example is not applied at all.