1

I have two properties, Related_Id and PageNumber. I want to bind these two values to a single label.

XAML code

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

current output: Related_Id

Desired output: Related_Id/ PageNumber

Could anyone help me to find a solution..

Thanks..

Nandu PH
  • 145
  • 1
  • 4
  • 10
  • 1
    Use a MultiBinding. – Clemens Aug 19 '16 at 08:09
  • [http://stackoverflow.com/questions/541896/concatenate-strings-instead-of-using-a-stack-of-textblocks](http://stackoverflow.com/questions/541896/concatenate-strings-instead-of-using-a-stack-of-textblocks) – JohnnyQ Aug 19 '16 at 08:12
  • See https://stackoverflow.com/questions/4399178/stringformat-and-multibinding-with-label for the correct solution – Geert Apr 18 '18 at 07:27

2 Answers2

2

Try this:

 <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>
Sameed
  • 655
  • 1
  • 5
  • 18
  • thanks for your help.. but I am getting the following error: The name "MultiBinding" does not exist in the namespace "http://schemas.microsoft.com/client/2007 – Nandu PH Aug 19 '16 at 10:39
  • well one more thing you can do is to make a read only property in which you concatenate Related_Id and PageNumber and then you can bind that to your label's content. Like this ' public string IDandPage { get { return RelatedId + "/" + PageNumber; } } ' – Sameed Aug 19 '16 at 11:51
-1

This is the code you're looking for :

<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>
ViVi
  • 4,339
  • 8
  • 29
  • 52
  • thanks for your help.. but I am getting the following error: The name "MultiBinding" does not exist in the namespace "http://schemas.microsoft.com/client/2007 – Nandu PH Aug 19 '16 at 10:39
  • @NanduPH: Is it working now? The above code works fine at my end. – ViVi Aug 20 '16 at 06:27