views:

16

answers:

2

Hello,

I am grouping data in a WPF DataGrid. that takes very long so I want to show a Loading bar/adorner.

I am using MVVM. How would you remove/fade out the loading bar/adorner when the datagrid has finished the grouping.

How do I get the moment when the Data is grouped 100% ? Can this somehow be set in xaml or retrieved etc... ?

A: 

I think you could use the ItemContainerGenerator.StatusChanged event. When the status will change to ContainersGenerated, the grouping is complete.

Note that it's just an assumption, but I suspect the containers are regenerated when you change the GroupDescriptions...

Thomas Levesque
I found a great example here:http://www.get-the-solution.net/index-1-14-69-IsAsync---Meldung-%26u.html
Lisa
Interesting, but I'm not sure it has anything to do with grouping...
Thomas Levesque
ah yes I could not anymore edit the comment... I still wanted to say that I maybe trash the grouping ;-)
Lisa
A: 

one solution could be to bind to the Visibilty of the Expander. Because only when all data is grouped the expander is visible. But this works only when you set the IsExpanded to TRUE, else the expander is visible immediately and the grouping happens when you click on the expander arrow.

My Expander is not expanded in default setting. So I tried to speed up the expanding of the expander by ripping the RowStyle and CellStyle. This is the minimum of xaml I could achieve without breaking my functionality of a not editable grid showing alternating BackGround

 <Style x:Key="DataGridRowStyle" TargetType="{x:Type DataGridRow}">               
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type DataGridRow}">
                            <Border Background="{TemplateBinding Background}" SnapsToDevicePixels="True">                                                            
                               <DataGridCellsPresenter Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>   
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}">
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="BorderBrush" Value="Transparent" />             
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type DataGridCell}">                          
                                <ContentPresenter />                
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">                     
                        <Setter Property="Foreground" Value="Red"/>                    
                    </Trigger>
                </Style.Triggers>
            </Style>

The expanding goes faster now I guess approximately 30-40%. At least I recognize it visually. :)

Lisa