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

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

问题描述

我试图将数据网格中的列的可见性绑定到ViewModel中的布尔DependencyProperty(在这种情况下,设置为View - 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 - 不是继承/

为了将来的猝死...

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天全站免登陆