简体   繁体   English

WPF依赖项属性继承

[英]WPF Dependency Property Inheritance

I have a scenario in which DP Inheritance is not working, my code can also be wrong. 我有一个无法使用DP继承的情况,我的代码也可能是错误的。

I have a Parent control with a bool Dependency Property "CanShow" on ViewModel. 我在ViewModel上有一个Bool依赖项属性“ CanShow”的父控件。 This enables/disables the button on this MainParent Window. 这将启用/禁用此MainParent窗口上的按钮。

Now, I want a property/DP on child VM, which can set the CanShow property of Parent from childVM to enable/disable the button. 现在,我想要子VM上的属性/ DP,可以从childVM设置Parent的CanShow属性以启用/禁用按钮。

Is this a scenario for Dependency Property Inheritance? 这是依赖项属性继承的方案吗? - Plz suggest. -Plz建议。

I hope so, the scenario is clear. 我希望这样,情况很清楚。

Thanks, 谢谢,

VJ VJ

No, inheritance does not work from child to parent, it works from parent to child. 不,继承不能在子代之间进行,而是在父子之间进行。 You will have to use some sort of event aggregation in order to propagate your event from child to parent which will change CanShow. 为了将事件从子级传播到父级,您将必须使用某种事件聚合,这将更改CanShow。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM