0

I have two textbox txtFName and txtLName . Now I want to display txtFName - txtLName in textblock using binding.

For bind only txtFName I write below code:

<TextBlock x:Name="textblock" Text="{Binding ElementName=txtFName , Path=Text}" Margin="-3,-8,0,0"/> 

But I want to display txtFName - txtLName in textblock using binding.

I do not want to write any code in code behind.

Thanks,

1
  • question is not clear. post ur expected output. Commented Jul 7, 2014 at 10:14

2 Answers 2

1

You can do that using MultiBinding:

<TextBlock> <TextBlock.Text> <MultiBinding StringFormat="{}{0} - {1}"> <Binding ElementName="txtFName" Path="Text"/> <Binding ElementName="txtLName" Path="Text"/> </MultiBinding> </TextBlock.Text> </TextBlock> 
Sign up to request clarification or add additional context in comments.

Comments

1

The content of a TextBlock is composed of a collection of inline objects, e.g. Runs. Therefore, you can bind txtFName and txtLName to two different runs, e.g. like this:

<TextBlock x:Name="textblock"> <Run Text="{Binding ElementName=txtFName, Path=Text}"/> <Run Text=" - "/> <Run Text="{Binding ElementName=txtLName, Path=Text}"/> </TextBlock> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.