XamDataGrid列可见性在使用MVVM时不起作用 [英] XamDataGrid column visibilty is not working using MVVM

查看:133
本文介绍了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时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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