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

问题描述

限时删除!!

我无法将 WPF 数据网格文本列的 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}}

我已检查转换器是否正常工作(可见性枚举的布尔值)并且在范围内.

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 是一个依赖属性,所以应该是可绑定的.

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.

问候,

马特

推荐答案

我解决了这个问题.

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 的 Visible 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 09:53