XamDataGrid列可见性在使用MVVM时不起作用

编程入门 行业动态 更新时间:2024-10-21 13:09:53
本文介绍了XamDataGrid列可见性在使用MVVM时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在MVVM体系结构中实现XamDataGrid列可见性,但这似乎行不通.

I'm trying to implement XamDataGrid column visibilty in a MVVM architecture and it does not seems to be working.

我正在执行以下操作:

为未绑定字段添加可见性属性-

Adding Visiblility property for an unbound field -

<igDP:UnboundField Name="gridCustomerId" Label="ID" Binding="{Binding customerid, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding ShowCustomerIDColumn, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">

在我的视图模型中,添加可见性类型:

In my View Model, adding a proerty of Visibility type:

//ToShow CustomerID Column private Visibility showCustomerIDColumn; public Visibility ShowCustomerIDColumn { get { return showCustomerIDColumn; } set { showCustomerIDColumn=value; InvokePropertyChanged("ShowCustomerIDColumn"); } }

然后使用以下代码在命令处理程序中:

Then in the command handler using the following code:

if(ShowCustomerIDColumn == Visibility.Hidden) ShowCustomerIDColumn = Visibility.Visible; else ShowCustomerIDColumn = Visibility.Hidden; InvokePropertyChanged("ShowCustomerIDColumn");

有解决方案的人吗?

干杯, Anshuman

Cheers, Anshuman

推荐答案

可见性在此处不起作用的主要原因是可见性不是Fields类中的依赖项属性(UnboundField类是从Field类派生的)

The main reason why visibility is not working here cause Visibility is not a dependency property in Fields Class(UnboundField class is derived from Field class) unlike other properties.

查看可见性属性

请参阅支持绑定的Label/RowSpan属性

您需要在c#代码中设置可见性(在某些行为或事件背后的代码中):

You need to set the visibility in c# code(either in some behavior or code behind event):

fieldlayout.Fields[node.Name].Visibility = node.Visibility ? Visibility.Visible : Visibility.Collapsed;

更多推荐

XamDataGrid列可见性在使用MVVM时不起作用

本文发布于:2023-11-11 18:15:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579202.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   见性   XamDataGrid   MVVM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!