开发者

Silverlight Custom Property Inheritance

开发者 https://www.devze.com 2023-02-09 19:13 出处:网络
I have a class inheriting from UserControl, with a custom DependencyProperty. I put a stan开发者_如何学JAVAdard button inside (not necessarily it\'s immediate child) and I want to get the value of my

I have a class inheriting from UserControl, with a custom DependencyProperty. I put a stan开发者_如何学JAVAdard 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)


It is available to a few native properties only. And you cannot enable it for custom properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消