【问题标题】:How can I collapse Silverlight DataGrid Groups using MVVM?如何使用 MVVM 折叠 Silverlight DataGrid 组?
【发布时间】:2010-06-10 22:11:36
【问题描述】:

我在 Silverlight 应用程序中使用 MVVM。因此,我使用 PagedCollectionView 作为我的视图模型的属性,将其绑定到 DataGrid ItemSource。但是我有这个要求:“加载用户控件时,Grid中的所有组都应该折叠。”。当我使用页面集合视图时,我使用了以下代码:

     this.PinesView = new PagedCollectionView(this.Pines);
     PinesView.GroupDescriptions.Add(new PropertyGroupDescription("Operador"));                        
     PinesView.GroupDescriptions.Add(new PropertyGroupDescription("Marca"));

现在我有了折叠组的代码,但是我发现的唯一一段代码需要在 UI 上运行,所以将它链接到我的 ViewModel 有点困难,因为该集合视图是异步填充的,所以我不知道如何传达关于集合已填充到 UI 以运行此代码;甚至更好的是,如何将折叠指令从我的 ViewModel 发送到 UI。

你能帮帮我吗?

【问题讨论】:

    标签: c# silverlight datagrid mvvm grouping


    【解决方案1】:
    public View()
    {
     InitializeComponent();
     datagrid.LoadingRowGroup += new EventHandler<DataGridRowGroupHeaderEventArgs>(datagrid_LoadingRowGroup);
    }
    
    void datagrid_LoadingRowGroup(object sender, DataGridRowGroupHeaderEventArgs e)
    {
     datagrid.LoadingRowGroup -= datagrid_LoadingRowGroup;
    
     foreach(CollectionViewGroup group in (datagrid.ItemsSource as PagedCollectionView).Groups)
     {
      datagrid.CollapseRowGroup(group, true);
     }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-24
      • 2011-07-11
      • 1970-01-01
      • 2010-12-24
      • 2020-03-09
      • 2012-12-17
      • 2013-12-17
      • 1970-01-01
      相关资源
      最近更新 更多