在WPF DataGrid中绑定DataGridColumn的可见属性 [英] Binding Visible property of a DataGridColumn in WPF DataGrid

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

问题描述

我无法将WPF datagridtextcolumn的Visible属性绑定到一个布尔值。

I cannot bind the Visible property of the WPF datagridtextcolumn to a boolean value.

我的绑定表达式是

{Binding Path=DataContext.IsThisColumnVisible, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window},Converter={StaticResource vc}}

我检查了转换器的工作原理(bool到可见性枚举)并在范围内。

I have checked that the converter works (bool to the visibility enum) and is in scope.

如果我对列的标题使用相同的表达式,则标题将按预期显示false。

If I use the same expression for the header of the column, the header displays 'false' as expected.

可见是一个依赖属性,因此应该是可绑定的。

Visible is a dependency property so should be bindable.

任何人看到我做错了什么?或者还有其他人能够绑定到可见的属性。

Anyone see what Im doing wrong? Or has anyone else been able to bind to the visible property.

请问,

Matt

推荐答案

我这样做了。

DataGridCOlumn不是一个框架元素,所以FindAncestor调用失败(DataGridColumn不是视觉树的一部分)

DataGridCOlumn is not a framework element so the FindAncestor call was failing (DataGridColumn not part of visual tree)

必须将绑定表达式的源属性设置为静态资源,它的工作正常。

Have to set source property of binding expression to a staticresource and it works fine.

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

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