2

別の SO ユーザーから提供されたヘルパー クラスを使用して、ラベルに文字列書式を適用しようとしています。ただし、彼のソリューションを適用すると、次のエラーが発生します。

The object 'Label' already has a child and cannot add ''. 'Label' can accept only one child.

ラベルは次のとおりです。

<Label Grid.Column="1"
       Grid.Row="1">
    <ui:Helper.Text>
        <PriorityBinding>
            <Binding Path="Worker.Employer.Name" StringFormat="Employer: {0}" />
            <Binding Source="Unemployed" />
        </PriorityBinding>
    </ui:Helper.Text>
    <Binding RelativeSource="{RelativeSource Self}" Path="(ui:Helper.Text)" />
</Label>

エラーは「Binding RelativeSource...」行を指しています。これを修正するにはどうすればよいですか? Labels の代わりにsを使用したいTextBlockのですが、それだけの価値がないところまで来ています。

4

2 に答える 2

3

添付プロパティContentLabel

Content実際に明示的にラップするだけです<Label.Content>

<Label Grid.Row="1"
       Grid.Column="1">
  <ui:Helper.Text>
    <PriorityBinding>
      <Binding Path="Worker.Employer.Name"
               StringFormat="Employer: {0}" />
      <Binding Source="Unemployed" />
    </PriorityBinding>
  </ui:Helper.Text>
  <Label.Content>
    <Binding Path="(ui:Helper.Text)"
             RelativeSource="{RelativeSource Self}" />
  </Label.Content>
</Label>
于 2013-06-21T20:41:49.487 に答える