Can we concat two properties together in binding expression? If possible without converter or without writing two textblocks and setting them individually?
相关问题
- VNC control for WPF application
- WPF Binding from System.Windows.SystemParameters.P
- XAML: Applying styles to nested controls
- How can I add a horizontal line (“goal line”) for
- How to properly change a resource dictionary
Like alpha-mouse suggests MultiBinding won't work out of the box, but this guy has thrown something together that might help:
http://www.olsonsoft.com/blogs/stefanolson/post/Improvements-to-Silverlight-Multi-binding-support.aspx
If that seems a bit rogue, then maybe try putting a combined value property on your object as a helper for the Binding mechanism, like:
It is possible in WPF with the help of MultiBinding and StringFormat. But not in Silverlight unfortunately.
You can add a new property with a getter that performs the concatenation.
Say you have
FirstName
andLastName
properties. You can then define aName
property as follows:This will work well, but you should be aware that you cannot do two-way binding for a read-only property. Also you may want to implement property changed notification for the concatenated property in the setters for the source properties.
If you want to show, say
FirstName
andLastName
, in a singleTextBlock
, then you can do like this:Now, the TextBlock's
Text
property will be"Sachin Tendulkar"
and will be displayed if:Hope that helps.
If you need to add any string, then try it. Here I add "%" after binding text in windows phone.
data1 and data2 are string properties which are binded.