0

I am doing a very simple thing which is to display the text like this in a Label:

LastName, FirstName 

My View is binded to the ViewModel which contains the FirstName and LastName properties. I want to do something like this:

<Label Content="{Binding LastName}, {Binding FirstName}"

Of course the above does not work. So, I concatenated the FirstName and LastName and returned as a FullName from the ViewModel and bind it like this:

  <Label Content="{Binding FullName}"/>

Is the above a better approach? Since, now I have to do the same thing with City, State.

john doe
  • 9,220
  • 23
  • 91
  • 167

1 Answers1

1

You can use MultiBinding

   <Label.Content>
            <TextBlock>
              <TextBlock.Text>
                <MultiBinding StringFormat="{}{0} + {1}">
                  <Binding  Path="City" />
                  <Binding  Path="State" />
                </MultiBinding>
              </TextBlock.Text>
            </TextBlock>
     </Label.Content>
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396