TabControl 在 Window.Show 上丢失选定的选项卡
我们有一个 MVVM (Cinch) 解决方案,其中有一个带有 TabControl 的窗口。 ItemsSource 绑定到 CollectionView(从 ObservableCollection 生成的 DefaultView),且 IsSynchronizedWithCurrentItem=true。第一次加载窗口时,一切都运行良好...选项卡正确显示,用户可以在它们之间切换。
当窗口隐藏并再次显示时会出现此问题。无论 CollectionView 中的 CurrentItem 是什么,始终会再次选择第一个选项卡。 .Show 之前的行将 CurrentItem 作为我们想要的选项卡,但选项卡在 .Show 操作期间切换。
还有其他人遇到过这个问题吗?
We have an MVVM (Cinch) solution that has a Window with a TabControl in it. The ItemsSource is bound to a CollectionView (DefaultView generated from an ObservableCollection), with IsSynchronizedWithCurrentItem=true. Everything works great the first time the Window loads... tabs are displaying correctly and the user can switch between them.
The problem occurs when the Window is hidden and shown again. The first tab is always selected again, regardless of what the CurrentItem in the CollectionView is. The line before the .Show has the CurrentItem as the tab we want, but the tab switches during the .Show operation.
Has anyone else run into this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这绝对是一个黑客行为。但是您可以覆盖已激活事件并在重置之前存储选项卡索引,并在重新激活时再次设置它。
This is definitely a hack. But you could override the Activated event and store the tab index before it gets reset and set it again when it reactivates.