WP7 local variable binding

I have a user interface element whose color I would like to set based on a local variable on the page (well, actually, in the module, but I can move it to the page).

I see that in WPF, you can bind the user interface element to a local variable by making the variable a property and setting the RelativeSource to the parent class using FindAncestor:

WPF binding to local variable

Unfortunately, Silverlight does not seem to support FindAncestor mode.

Any possible solution, or do I need to instantiate a custom class and such only for this variable?

+5
source share
2 answers

Over the past few weeks, I have hopped many times from Silverlight to WPF, so the following idea may or may not fly.

Does your page have a name property set on it? If not, set it (x: Name = "MyPage").

then you can do:

Fill="{Binding ElementName=MyPage, Path=MyProperty}"

Give it a try (just from the head)

+7
source

All Articles