dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.04k stars 1.17k forks source link

DataGrid.ScrollIntoView not works when DataGrid is grouping #4606

Closed GF-Huang closed 3 years ago

GF-Huang commented 3 years ago
ryalanms commented 3 years ago

Thanks, @GF-Huang. Could you provide a repro project? Thanks.

daisyTian0517 commented 3 years ago

@GF-Huang I used below code to scroll into line 21 of DataGrid

int rowindex = 20;
dataGrid.ScrollIntoView(dataGrid.Items[rowindex]);

It works well as: 3

Is that the same as your usage?

GF-Huang commented 3 years ago

Did you use a custom group template?

daisyTian0517 commented 3 years ago

Yes, my xaml code is:

<Window.Resources>
        <Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type GroupItem}">
                        <Expander IsExpanded="True">
                            <Expander.Header>
                                <TextBlock Text="{Binding Path=Name}"/>
                            </Expander.Header>
                            <ItemsPresenter />
                        </Expander>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <DataGrid Name="dataGrid" Width="600" Height="250"  HorizontalAlignment="Left" VerticalAlignment="Top">
            <DataGrid.GroupStyle>
                <GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <DataGridRowsPresenter/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </DataGrid.GroupStyle>
        </DataGrid>
        <Button Content="Button" HorizontalAlignment="Left" Margin="226,325,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
    </Grid>
GF-Huang commented 3 years ago

These make it works, thanks.

<GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <DataGridRowsPresenter/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>