datagrid在滚动时,滚动滚动时会重新排序
当我运行此功能时,它会收到相当大的项目列表。起初向下滚动根本没有任何问题。但是,当我向上滚动时,它开始来回毛刺,您永远无法到达数据杂志的顶部。甚至更多的行开始融合在一起,不再坐在应该的位置。
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您拥有的绑定语句:
暗示您的视野背后有一个奇怪的结构。它需要进行扁平化,因此您要数据限定到
workItems
,而不是context.workitempanelcontext.workitems
。阅读Demeter定律。
我建议您将MVVM读取为设计模式并重组您的数据,以使其比现在更具约束力的友好和更平坦。
看来您有一个
上帝对象
称为上下文
,它绝对有所有内容,这不是一个好的设计选择。除了我提到的深刻绑定外,该代码中没有任何表明它应该像这样的行为。
The binding statement you have:
Is suggesting you have an odd structure behind your view. It needs flattening so you are databinding to
WorkItems
, notContext.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
calledContext
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.