对派生的 ObservableCollection的渲染项目重新排序在 PropertyChange 上的 ItemsControl 中
我有一个 ItemsControl 绑定到排序(通过 CollectionViewSource)派生的视图模型 ObservableCollection。在我的派生集合类中,我正在视图模型上处理 PropertyChanged。当某个属性(顺序)发生更改时,我需要呈现控件以反映新的排序集合。
据我所知,在处理 PropertyChanged 时,我可以调用 OnCollectionChanged 并指定 Reset 操作;然而,这会导致失去对控制的关注,这对我的情况来说是不可取的。
无论如何,我可以处理更改并在光标保留在原处的情况下进行平滑过渡(或者在选项卡的情况下,移动到下一个适当的字段)。
I have an ItemsControl bound to a sorted (via CollectionViewSource) derived ObservableCollection of view models. In my derived collection class, I'm handling PropertyChanged on my view models. When a certain property (Order) has changed I need the rendering of the controls to reflect the new, sorted collection.
I understand, that in my handling of PropertyChanged, I can call OnCollectionChanged with the Reset action specified; however, this leads to loss of focus on the control, which is undesirable for my situation.
Is there anyway I can handle the change and have a smooth transition with the cursor remaining where it is (or in the case of a tab, move to the next appropriate field).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Order
属性发生了什么变化?也许您可以考虑重新排列 ItemsControl,而不是排序和刷新源。
我过去用 TabControl 做过这个。当用户将选项卡拖放到新位置时,它会从 TabControl 中删除实际的 TabItem 并将其插入新位置。 SelectedTab 从未改变,因此我不必担心焦点改变。
What changes the
Order
property?Perhaps you can look into re-arranging your ItemsControl instead of sorting and refreshing your source.
I did this in the past with a TabControl. When a user Drags/Drops a tab into a new location, it removes the actual TabItem from the TabControl and inserts it in the new location. The SelectedTab was never altered so I didn't have to worry about focus changing.