Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The property 'Content' is set more than once when I add Style

Tags:

c#

wpf

When I use this:

<Label Grid.Column="2"
       Grid.Row="8" 
       Content="{x:Static res:Strings.ToolPanelEditView_Validation_MandatoryField}" >
</Label>

It runs just fine.

But when I add the Style tag:

 <Label Grid.Column="2"
        Grid.Row="8" 
        Content="{x:Static res:Strings.ToolPanelEditView_Validation_MandatoryField}" >
    <Style>
        <Setter Property="Label.Margin" Value="0" />
    </Style>
</Label>

It doesn't compile saying:

The property 'Content' is set more than once

like image 666
user1028741 Avatar asked Jul 28 '15 16:07

user1028741


1 Answers

Because you set the content property twice. Putting more elements inside an element is the same thing as setting the content property without some additional information

Whenever you are looking to set a property besides content from inside the element you need to wrap it in <Element.Property>

<Label  Grid.Column="2"  Grid.Row="8" Content="{x:Static res:Strings.ToolPanelEditView_Validation_MandatoryField}" >
  <Label.Style>
    <Style>
        <Setter Property="Label.Margin" Value="0" />
    </Style>
  </Label.Style>
</Label>

is what you want

like image 142
pquest Avatar answered Nov 07 '22 22:11

pquest