WPf: binding to multiple properties at the same time
I have a list in which I am using a binding to display my information. I am using a simple data template. Is there a way to link two data in one control. I would like to replace with something like:
<code>
<TextBlock Text = "{Binding LName}" />
<TextBlock Text = "," />
<TextBlock Text = "{Binding NName}" />
code>
to something like
<TextBlock Text = "{Binding LName} + ',' + {Binding FName}" />
thank
source to share
If you're using WPF 3.5SP1 or higher, you don't need to write your own value converter for your use case. Instead, just use StringFormat
:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}, {1}">
<Binding Path="LName" />
<Binding Path="FName"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
source to share
Yes. You would use MultiBinding along with IMultiValueConverter .
The MultiBinding help shows an example doing exactly what you are trying to do - binding one textbox to the first + last names.
source to share