Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we concat two properties in data binding?

Can we concat two properties together in binding expression? If possible without converter or without writing two textblocks and setting them individually?

like image 373
TCM Avatar asked Dec 01 '10 14:12

TCM


2 Answers

If you want to show, say FirstName and LastName, in a single TextBlock, then you can do like this:

<TextBlock>      <Run Text="{Binding FirstName}" />      <Run Text="   " /> <!-- space -->      <Run Text="{Binding LastName}" /> </TextBlock> 

Now, the TextBlock's Text property will be "Sachin Tendulkar" and will be displayed if:

FirstName = Sachin LastName  = Tendulkar 

Hope that helps.

like image 51
Nawaz Avatar answered Sep 23 '22 17:09

Nawaz


<TextBlock.Text>    <MultiBinding StringFormat="{}{0} , {1}">      <Binding Path="data1" />      <Binding Path="data2" />     </MultiBinding> </TextBlock.Text> 

data1 and data2 are string properties which are binded.

like image 44
Kiran k g Avatar answered Sep 23 '22 17:09

Kiran k g