I'm using MVVM in a Silverlight application. So I use a PagedCollectionView as property of my View Model to bind it to a DataGrid ItemSource. But I have this requirement: "all groups in the Grid should be collapse when the user control is loaded.". As I'm using a Page collection View I used this code:
this.PinesView = new PagedCollectionView(this.Pines);
PinesView.GroupDescriptions.Add(new PropertyGroupDescription("Operador"));
PinesView.GroupDescriptions.Add(new PropertyGroupDescription("Marca"));
Now I have the code to collapse the groups, but the only piece of code I found needs to run over the UI, so开发者_运维问答 It's kinda difficult to link it to my ViewModel because that collectionview is filled Async, so I don't know how to comunicate about the collection is already filled to the UI to run this code; or even better, how to send that collapse instruction from my ViewModel to the UI.
Could you please help me?
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);
}
}
精彩评论