String format using MultiBinding?

后端 未结 1 661
误落风尘
误落风尘 2020-12-01 06:44

I\'m trying to display a string in XAML using Label control. Following is my XAML code :

相关标签:
1条回答
  • 2020-12-01 06:49

    you are trying to bind a string to an object. But StringFormat requires its target to be a string type.

    try putting a TextBlock in your label content and bind your data to it

    <StackPanel>
      <Slider x:Name="sl1" Minimum="10" Maximum="100"/>
      <Slider x:Name="sl2" Minimum="10" Maximum="100"/>
      <Label x:Name="label13" Background="Yellow" Foreground="Black">
        <Label.Content>
            <TextBlock>
              <TextBlock.Text>
                <MultiBinding StringFormat="{}{0} x {1} Test">
                  <Binding ElementName="sl1" Path="Value" />
                  <Binding ElementName="sl2" Path="Value" />
                </MultiBinding>
              </TextBlock.Text>
            </TextBlock>
        </Label.Content>
      </Label>
    </StackPanel>
    

    EDIT your class Movie must implement the INotificationPropertyChanged interface and your two properties must raise the property changed event with their proprty names!

    hope this helps

    0 讨论(0)
提交回复
热议问题