WP7绑定到本地变量 [英] WP7 Binding to Local Variable
问题描述
我有一个UI元素,其颜色,我想基于页面的局部变量设置(以及实际的模块,但我可以把它移动到页面)。
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).
我在WPF一见可以通过该变量的属性和使用的 FindAncestor 的设置绑定的的RelativeSource 的父类的UI元素一个局部变量绑定:
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:
不幸的是Silverlight的似乎不支持的 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?
推荐答案
我一直Silverlight的跳过去几周WPF很多,所以下面的想法可能会或可能不会飞。
Ive been jumping from Silverlight to WPF a lot over the last few weeks, so the following idea may or may not fly.
您的页面是否有名称属性设置就可以了?如果不是,设置它(X:名称='我的空间)。
Does your page have the name property set on it? If not, set it (x:Name="MyPage").
那么你可以这样做:
Fill="{Binding ElementName=MyPage, Path=MyProperty}"
给一个尝试(只是把我的头顶部)
Give that a try (just off the top of my head)
这篇关于WP7绑定到本地变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!