WP7 Binding to Local Variable

大憨熊 提交于 2019-12-01 03:48:50

问题


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?


回答1:


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)




回答2:


Check these posts:

RelativeSource Binding with FindAncestor mode in Silverlight

Silverlight Binding Markup Extension

Hope this will help you.



来源:https://stackoverflow.com/questions/4912452/wp7-binding-to-local-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!