繁体   English   中英

添加Style时,属性'Content'被设置多次

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

我用这个时:

<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>

它没有编译说:

属性“内容”设置不止一次

因为您设置了两次内容属性。 在元素中放置更多元素与设置content属性没有一些额外信息是一回事

每当您想要在元素内部设置除内容之外的属性时,您需要将其包装在<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>

是你想要的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM