Silverlight - Sample Data - Complex objects
I really like using the sample data binding at design time for Silverlight.
It is easy to use it when you need to return string values.
In my case, I am trying to bind to my ViewModel one of whose properties returns a SolidColorBrush. How do I setup the sample data to return a SolidColorBrush value?
开发者_运维百科Here is what the string based properties look in the sampleData.xml file.
<ViewModels:MyViewModel AlphaValue="Abcd" ColorValue="????"/>
How should I format ColorValue to return a SolidColorBrush?
What I am trying to do: I have a textblock with its foreground set to Foreground="{Binding ColorValue}". The TextBlock is invisible on the design surface as its not getting a value from the sampledata.xml file. Where as another textblock on which I have only text property set to a binding value, appears correctly on the design surface.
You need to look at creating a value converter. Look at this and it should give you an understanding of what you need to do. http://msdn.microsoft.com/en-us/library/system.windows.data.binding.converter.aspx
精彩评论