I have a UI element whose color I'd like to set based on a local variable in the page (well actually in a module, but I can move it to the page).
I see in WPF one can bind a UI element to a local variable by making the variable a property and setting the binding RelativeSource to the parent class using FindAncestor :
Unfortunately Silverlight doesn't seem to support FindAncestor mode.
Any possible solution, or do I have to create an instance of a custom class and such just for this one variable?
Ive been jumping from Silverlight to WPF a lot over the last few weeks, so the following idea may or may not fly.
Does your page have the name property set on it? If not, set it (x:Name="MyPage").
then you can do:
Fill="{Binding ElementName=MyPage, Path=MyProperty}"
Give that a try (just off the top of my head)
Check these posts:
RelativeSource Binding with FindAncestor mode in Silverlight
Silverlight Binding Markup Extension
Hope this will help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.