我正在尝试在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时不起作用
发布评论