Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP7 Binding to Local Variable

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:

WPF Binding to local variable

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?

like image 285
amb9800 Avatar asked Feb 06 '11 09:02

amb9800


1 Answers

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)

like image 163
Mark Avatar answered Sep 19 '22 19:09

Mark