XAML在标签内容中绑定多个属性

本文关键字:绑定 属性 标签 XAML | 更新日期: 2023-09-27 18:03:00

我有两个属性,Related_Id和PageNumber。我想把这两个值绑定到一个标签上。

XAML代码
<StackPanel>
    <sdk:Label x:Name="RelatedItemIdLabel"  
    HorizontalAlignment="Left"
    VerticalAlignment="Top"
    Content="{Binding CreateMessage.RelatedId}" />
</StackPanel>

当前输出:Related_Id

期望输出:Related_Id/PageNumber

有谁能帮我找到一个解决方案吗?

谢谢. .

XAML在标签内容中绑定多个属性

试试这个:

 <Label x:Name="RelatedItemIdLabel"
           HorizontalAlignment="Left"
           VerticalAlignment="Top">
        <Label.Content>
            <MultiBinding StringFormat=" {0}/{1}">
                <Binding Path="" /> //insert field 1
                <Binding Path="" /> //insert field 2
            </MultiBinding>
        </Label.Content>
    </Label>

这是你要找的代码:

<StackPanel>
    <sdk:Label x:Name="RelatedItemIdLabel"  
    HorizontalAlignment="Left"
    VerticalAlignment="Top">    
    <sdk:Label.Content>
        <MultiBinding StringFormat=" {0}, {1}">
            <Binding Path="{Binding CreateMessage.RelatedId}"/>
            <Binding Path="{Binding CreateMessage.PageNumber}"/>
        </MultiBinding>
    </sdk:Label.Content>    
    </sdk:Label>
</StackPanel>