绑定 DataGridTemplateColumn 可见性 [英] Bind DataGridTemplateColumn Visibility

查看:42
本文介绍了绑定 DataGridTemplateColumn 可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将数据网格中列的可见性绑定到 ViewModel 中的布尔 DependencyProperty(在本例中设置为视图的数据上下文 - UserControl).出于某种原因(我似乎不明白)它只是不起作用.

I am trying to bind the visibility of a column in a datagrid to a boolean DependencyProperty in the ViewModel (Set as data context of the View - UserControl in this case). For some reason (I don't seem to understand) it just doesn't work.

在这里查看后,我发现 datagridtemplate(和任何其他模板)不是可视化树的一部分.所以我无法绑定它.

After looking here I found out that the datagridtemplate (and any other template) is not part of the visual tree. So I can't bind to it.

该问题的任何简单解决方案(当然不会破坏 MVVM 模式)?

Any simple solution to the problem (without breaking the MVVM pattern of course) ?

推荐答案

在这里找到解决方案:
http://www.thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/
对于未来的问题...

Found the solution here:
http://www.thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/
For future quenstions...

这篇关于绑定 DataGridTemplateColumn 可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆