WPF 通过绑定隐藏 DataGridColumn
由于某种原因,我无法隐藏 WPF Toolkit 的 DataGridColumn。我正在尝试执行以下操作:
<dg:DataGridTemplateColumn Header="Item Description" Visibility="{Binding IsReadOnly}">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=ItemDescription}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
这不起作用,因为它正在寻找 ItemSource 上的 IsReadOnly 属性(而不是当前类的属性)。 如果将此添加为实现 INoifyPropertyChanged 的 ItemSource 类的属性,它仍然不会隐藏该列。有办法解决这个问题吗?我希望当单击按钮更改 IsReadOnly 属性时隐藏该列。
假设 IsReadOnly 返回一个可见性值并且是一个依赖属性
我完全陷入困境,我真的很感谢您的帮助!多谢!
For some reason I can't hide WPF Toolkit's DataGridColumn. I am trying to do the following:
<dg:DataGridTemplateColumn Header="Item Description" Visibility="{Binding IsReadOnly}">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=ItemDescription}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
This doesn't work, since it's looking for a IsReadOnly property on the ItemSource (not a property of the current class).
If add this as a property of the ItemSource class that implements INoifyPropertyChanged, it still doesn't hide the column. Is there a way around this? I want the column to hid when a button click changes IsReadOnly property.
Assume IsReadOnly returns a Visibility value and is a dependency property
I am completely stuck, I would really appreciate the help! Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
发表在这个问题中:
WPF DataGrid:将 DataGridColumn 可见性绑定到 ContextMenu MenuItems Ischeked (MVVM)
Fubzot 使用的绑定代码类似于
您可能还想查看一下:
将 DataGrid 的 DataContext 转发到其' columns..
这也链接在上面的问题中。
仅供我参考:您是否在使用当前代码的输出窗口中看到任何绑定错误?
Posted in this question:
WPF DataGrid: Binding DataGridColumn visibility to ContextMenu MenuItems Ischeked (MVVM)
Fubzot is using the binding code similar to
You may also want to check out this:
Forwarding the DataGrid’s DataContext to its’ columns..
which is also linked in the above question.
Just for my information: Do you see any Binding errors in your Output window using your current code?
如果您想绑定到
DataGridColumn
的IsReadOnly
属性,只需将RelativeSource
添加到 Binding(和转换器)即可:另外,它看起来此 StackOverflow 问题可能与您的问题有关。
If you want to bind to the
DataGridColumn
'sIsReadOnly
property, just add aRelativeSource
to the Binding (and a converter):Also, it looks like this StackOverflow question might be related to your problem.
您需要使用转换器
,然后在 XAML 中使用转换器。 示例
you need to use a converter
then you use the converter in the XAML. SAMPLE