Silverlight Data Binding a Property to an Expression of Another One or Multiple Properties
I've been using Flex for Flash development. And the data binding in Flex is really powerful.
Now I'm working on a Silverlight project开发者_StackOverflow社区. I just want to bind a control's property to an expression of another one or multiple properties. For example:
<Button Name="myButton" Background="{Binding myButton.IsEnabled ? #AABBCC : #DDEEFF}" />
It's actually a very simple and common case. I just want to my myButton.Background
to be #AABBCC
when the button is enabled, and #DDEEFF
if disabled.
Of course, I also want to bind my Background
property to multiple properties of other control(s).
In Flex, it's very simple. But I don't know how to do it in Silverlight.
Thanks.
Peter
Edits on Jan 3, 2012
http://www.codeproject.com/KB/silverlight/SilverlightMultiBinding.aspx
After the Silverlight 5 release and the above nice article. My needs can be done with a converter (inherits MarkupExtension
and implements IMultiValueConverter
).
In the bool to color case, you need a Converter. (MSDN)
For the multiple binding case it is my understanding that you can't bind to multiple values or properties.
You will have to bind to just one property en let that property resolve the value you need. (You can always change the property you are bound to at runtime, but you can only bind to one property at a time)
精彩评论