当我使用它时:
<Label Grid.Column="2"
Grid.Row="8"
Content="{x:Static res:Strings.ToolPanelEditView_Validation_MandatoryField}" >
</Label>
它运行得很好。
但是当我添加 Style 标签时:
<Label Grid.Column="2"
Grid.Row="8"
Content="{x:Static res:Strings.ToolPanelEditView_Validation_MandatoryField}" >
<Style>
<Setter Property="Label.Margin" Value="0" />
</Style>
</Label>
它不会编译说:
The property 'Content' is set more than once
最佳答案
因为您设置了两次内容属性。在一个元素中放置更多的元素与设置内容属性没有任何额外信息是一回事
无论什么时候你想要设置元素内部内容以外的属性,你都需要将它包装在 <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>
是你想要的
关于c# - 添加 Style 时多次设置属性 'Content',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31681961/