c# - 如何使用 MVVM 折叠 Silverlight DataGrid 组?

标签 c# silverlight datagrid mvvm grouping

我在 Silverlight 应用程序中使用 MVVM。因此,我使用 PagedCollectionView 作为我的 View 模型的属性,将其绑定(bind)到 DataGrid ItemSource。但是我有这个要求:“加载用户控件时,网格中的所有组都应该折叠起来。”。当我使用页面 Collection View 时,我使用了这段代码:

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

现在我有了折叠组的代码,但我发现的唯一一段代码需要在 UI 上运行,所以很难将它链接到我的 ViewModel,因为该 Collection View 是异步填充的,所以我不这样做知道如何向 UI 传达已填充的集合以运行此代码;或者更好的是,如何将折叠指令从我的 ViewModel 发送到 UI。

你能帮帮我吗?

最佳答案

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);
 }
}

关于c# - 如何使用 MVVM 折叠 Silverlight DataGrid 组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3018917/

相关文章:

c# - 此提交失败,错误代码为 2003,1201

silverlight - 如何禁用 Windows Phone 7 启动画面?

wpf - 如何从另一个 ".cs"文件中获取 DataGrid.SelectedIndex?(MVVM)

c# - 修改 Silverlight DataGrid 中的父数据行

java - Apache 点燃: ScanQuery giving exception

c# - 使用 Task.Delay 或 Task.Run 启动任务的区别

c# - 如何防止颜色混合?

c# - 无法解析远程名称 : 'api-3t.sandbox.paypal.com'

c# - 依赖属性 : PropertyChangedCallBack only called once

silverlight - 使用 Silverlight 文本框在插入符号位置插入