依赖属性优先级。我希望本地值可以被覆盖
我正在编写一个自定义控件。它有一个由控件提供“默认”值的依赖属性。该值可以随时更改。
我希望能够通过样式或其他方式覆盖此值,但 WPF 施加的依赖属性优先级意味着我的本地默认值始终获胜。
编写控件时是否有任何方法可以遵循其他来源?
I am writing a custom control. It has a dependency property that is supplied a "default" value by the control. This value can change at any time.
I want to be able to override this value via a style or whatever, but the dependency property precedence imposed by WPF means that my local default value always wins.
Is there any way of deferring to other sources when writing a control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试通过
DependencyObject.ClearValue()
。我认为您无法更改依赖属性的优先顺序 。You could trying clearing the local value via
DependencyObject.ClearValue()
. I don't think you can change the order of precedence for dependency properties.我想我已经找到解决办法了。
我现在公开两个属性。控件更新的“默认”控件和标准控件。在我的默认控件样式中,我将标准控件样式绑定到默认控件样式,以便它获取值,但仍然可以绑定到 xaml 中的其他内容。
I think I've found a way around it.
I now expose two properties. A "Default" one that the control updates, and a standard one. In my default control style I bind the standard one to the default one so it gets the values, but can still be bound to something else in the xaml.