Silverlight 自定义属性继承
我有一个继承自 UserControl 的类,具有自定义 DependencyProperty。我在里面放了一个标准按钮(不一定是直接子按钮),我想获取按钮上自定义 DP 的值,如下所示:
usercontrol.MyDependency = "hello";
var x = button.GetValue(MyUserControl.MyDependencyProperty);
它几乎是可视化树内的属性继承,但 x 为 null,而不是“hello” ”。
在 silverlight 中可以实现这样的属性继承吗?
(不,我不想将 userControl 放入它自己的 DataContext 中,我需要 ViewModel 的 DC,MyDependency 是视图的属性,而不是视图模型的属性)
I have a class inheriting from UserControl, with a custom DependencyProperty. I put a standard button inside (not necessarily it's immediate child) and I want to get the value of my custom DP on the button, like this:
usercontrol.MyDependency = "hello";
var x = button.GetValue(MyUserControl.MyDependencyProperty);
It's pretty much property inheritance inside the visual tree, but x is null, instead of "hello".
Is property inheritance like this possible in silverlight?
(And no, I do not want to put userControl into its own DataContext, I need the DC for my ViewModel, MyDependency is a property of the view, not the viewmodel)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它仅适用于少数本机属性。并且您无法为自定义属性启用它。
It is available to a few native properties only. And you cannot enable it for custom properties.