datagrid在滚动时,滚动滚动时会重新排序

发布于 2025-01-27 22:04:09 字数 1619 浏览 3 评论 0原文

当我运行此功能时,它会收到相当大的项目列表。起初向下滚动根本没有任何问题。但是,当我向上滚动时,它开始来回毛刺,您永远无法到达数据杂志的顶部。甚至更多的行开始融合在一起,不再坐在应该的位置。

<DataGrid 
        Grid.Row="1"
        CanUserResizeColumns="True"
        CanUserReorderColumns="False"
        CanUserSortColumns="False"
        IsReadOnly="True"
        HeadersVisibility="All"
        HorizontalAlignment="Stretch"
        VerticalAlignment="Stretch"
        AutoGenerateColumns="False"
        GridLinesVisibility="All"
        MaxColumnWidth="500"
        HorizontalScrollBarVisibility="Visible"
        VerticalScrollBarVisibility="Visible"
        Background="{Binding Context.UniversalSettingsContext.BackgroundColor}"
        Items="{Binding Context.WorkItemPanelContext.WorkItems}"
        >
        <DataGrid.Columns>
            <DataGridTemplateColumn Header="Allow?">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox IsThreeState="False" IsChecked="{Binding IsChecked}" HorizontalAlignment="Right"/>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTextColumn Binding="{Binding Id}" Header="Id" />
            <DataGridTextColumn Binding="{Binding State}" Header="State" />
            <DataGridTextColumn Binding="{Binding Description}" Header="Description" />
            <DataGridTextColumn Binding="{Binding ReleaseNotes}" Header="Release Notes" />
        </DataGrid.Columns>

</DataGrid>

When I run this, it gets a fairly large list of items. At first scrolling downwards has no issues at all. However when I scroll upwards it starts glitching back and forth and you can never reach the top of the DataGrid. Even more the rows start to get mixed up and no longer sit in the position they're supposed to.

<DataGrid 
        Grid.Row="1"
        CanUserResizeColumns="True"
        CanUserReorderColumns="False"
        CanUserSortColumns="False"
        IsReadOnly="True"
        HeadersVisibility="All"
        HorizontalAlignment="Stretch"
        VerticalAlignment="Stretch"
        AutoGenerateColumns="False"
        GridLinesVisibility="All"
        MaxColumnWidth="500"
        HorizontalScrollBarVisibility="Visible"
        VerticalScrollBarVisibility="Visible"
        Background="{Binding Context.UniversalSettingsContext.BackgroundColor}"
        Items="{Binding Context.WorkItemPanelContext.WorkItems}"
        >
        <DataGrid.Columns>
            <DataGridTemplateColumn Header="Allow?">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox IsThreeState="False" IsChecked="{Binding IsChecked}" HorizontalAlignment="Right"/>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTextColumn Binding="{Binding Id}" Header="Id" />
            <DataGridTextColumn Binding="{Binding State}" Header="State" />
            <DataGridTextColumn Binding="{Binding Description}" Header="Description" />
            <DataGridTextColumn Binding="{Binding ReleaseNotes}" Header="Release Notes" />
        </DataGrid.Columns>

</DataGrid>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卷耳 2025-02-03 22:04:09

您拥有的绑定语句:

Context.WorkItemPanelContext.WorkItems

暗示您的视野背后有一个奇怪的结构。它需要进行扁平化,因此您要数据限定到workItems,而不是context.workitempanelcontext.workitems

阅读Demeter定律。

我建议您将MVVM读取为设计模式并重组您的数据,以使其比现在更具约束力的友好和更平坦。

看来您有一个上帝对象称为上下文,它绝对有所有内容,这不是一个好的设计选择。

除了我提到的深刻绑定外,该代码中没有任何表明它应该像这样的行为。

The binding statement you have:

Context.WorkItemPanelContext.WorkItems

Is suggesting you have an odd structure behind your view. It needs flattening so you are databinding to WorkItems, not Context.WorkItemPanelContext.WorkItems.

Have a read of the Law of Demeter.

I would suggest having a read around MVVM as a design pattern and reorganise your data so it's a much more binding friendly and flatter than it is now.

It looks like you have one god object called Context that has absolutely everything on it which is not a good design choice.

There isn't anything in this code that suggest it should be behaving like this other than the deep binding I've mentioned.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文