I have a TextBlock:
<TextBlock x:Name="someText" Text="{Binding ElementName=theList, Path=SelectedItem.Name, Mode=TwoWay}" />
And as you can see, it is bound to another element's selected item. Now, let's just say that, for example, the selected item says "Hello, ". And I want to append my name to it (in XAML, not code-behind), so that it reads like: "Hello, Arrow.". How can I do this?
Try this:
<TextBlock x:Name="someText" TextWrapping="NoWrap">
<Run Text="{Binding ElementName=theList, Path=SelectedItem, Mode=TwoWay}" />
<Run Text=" Arrow." />
</TextBlock>
XAML solutions not available yet on Metro XAML:
You can use StringFormat:
<TextBlock x:Name="someText" Text="{Binding ElementName=theList, Path=SelectedItem, Mode=TwoWay, StringFormat={}{0} Arrow.}" />
Also you can use MultiBinding and StringFormat:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} Arrow.">
<Binding ElementName="theList" Path="SelectedItem.Name" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
With this configuration the only thing you could do is have that text in the selected item. So, what I would recommend is something more along these lines:
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="someText"
Text="{Binding ElementName=theList,
Path=SelectedItem.Name,
Mode=TwoWay}" />
<TextBlock x:Name="suffixText"/>
</StackPanel>
With this configuration you can provide the suffixText
any way you want and get the results you're looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With