Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of display corruption during horizontal scroll in WPF4 DataGrid with grouping?

I'm trying to create a datagrid with grouping and I'm getting display corruption (blank areas) during horizontal scrolling. The issue appears only when there is a GroupStyle.ContainerStyle defined. The datagrid should contain 200 rows or more to reproduce the problem.

UPDATE2: Related Microsoft Connect feedback.

UPDATE: Microsoft guy at social.msdn.com pointed out that adding grouping turns off datagrid virtualization. Possibly that's the root of the problem. I removed grouping from my sample and set VirtualizingStackPanel.IsVirtualizing to false and got exactly the same kind of corruption.

Code to reproduce the problem:

<DataGrid ItemsSource="{Binding Source={StaticResource ResourceKey=cvsGoods}}"
          CanUserAddRows="False" CanUserReorderColumns="False"
          CanUserDeleteRows="False" CanUserResizeRows="False"
          CanUserSortColumns="False" AutoGenerateColumns="True">
    <DataGrid.GroupStyle>
        <GroupStyle>
            <GroupStyle.ContainerStyle>
                <Style TargetType="{x:Type GroupItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type GroupItem}">
                                <ItemsPresenter  />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </GroupStyle.ContainerStyle>
        </GroupStyle>
    </DataGrid.GroupStyle>
</DataGrid>

After several horizontal scrolls to the right and back to the left blank areas appear on the left side. I tried it on WinXP and Win7.

The question is: how to get rid of that bug? Is there any workaround? Any suggestions?

Screenshot illustrating the problem:

Display corruption

like image 823
Dmitry Avatar asked Oct 24 '22 15:10

Dmitry


1 Answers

We once faced the same issue (but not the same cause) i.e. the datagrid will have blank areas just before the first column of some of the rows. The way we solved (a hack) it at that time was by disabling the rowheader (don't know how it solved the problem but did figure out that the blank areas were actually rowheaders).

We disabled (correct word would be made it size-zero) the rowheader by setting the width to zero, something like the code below:

<wpftk:DataGrid>
...
...
<wpftk:DataGrid.RowHeaderStyle>
    <Style  TargetType="wpftk:DataGridRowHeader" >
        <Setter Property="Width" Value="0" />
        <Setter Property="MaxWidth" Value="0" />
    </Style>
</wpftk:DataGrid.RowHeaderStyle>
...
...
</wpftk:DataGrid>

Let me know if it works in your case.

One more thing we noticed that if we either disable the virtualization or rowheaderstyle, it would solve our problem. We went for disabling the rowheader as we didn't need it.

like image 107
publicgk Avatar answered Oct 27 '22 03:10

publicgk