2010-06-10 83 views
2

我在Silverlight应用程序中使用MVVM。所以我使用PagedCollectionView作为View Model的属性,将它绑定到DataGrid ItemSource。但是我有这样的要求:“加载用户控件时,网格中的所有组都应该崩溃”。由于我使用的页面集查看我用这个代码:如何使用MVVM折叠Silverlight DataGrid组?

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

现在我的代码崩溃的群体,但代码的唯一的一块,我发现需要在用户界面上运行,所以它有点困难将其链接到我的ViewModel,因为该集合视图是填充异步,所以我不知道如何沟通有关集合已经填充到用户界面运行此代码;或者甚至更好,如何将我的ViewModel的折叠指令发送到UI。

你能帮我吗?

回答

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

+1这个工作,即使它不是技术上MVVM。 – McGarnagle 2012-09-12 23:08:19

相关问题