当页面的数据上下文用于其他绑定时,如何绑定到 WPF 依赖属性?
当页面的数据上下文用于其他绑定时,如何绑定到 WPF 依赖属性? (简单的问题)
How to bind to a WPF dependency property when the datacontext of the page is used for other bindings? (Simple question)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
需要设置元素的数据上下文。
XAML:
C#:
另请参阅此相关问题:
WPF DependencyProperties
The datacontext of the element needed to be set.
XAML:
C#:
Also see this related question:
WPF DependencyProperties
在 XAML 中:
在代码中:
尽管通常您会以相反的方式执行此操作,并将 UI 属性绑定到自定义依赖项属性。
In XAML:
In code:
Though usually you will do this the other way round and bind the UI property to the custom dependency property.