有没有办法取消 TabControl.Items.CurrentChanging?
不幸的是,没有 TabControl.SelectionChanging 事件(Selector.SelectionChanging),我正在努力实现此行为,以便我可以取消更改请求。
我尝试处理 TabControl.Items.CurrentChanging
(Items
属性是和 ItemCollection
)事件设置 e.Cancel (CurrentChangingEventArgs
) 为 true,但 UI 会使用新选项卡进行更新,尽管集合中的项目未发生更改。
有什么方法可以防止用户在不满足条件时切换到不同的 TabItem
吗?
There is unfortunately no TabControl.SelectionChanging event (Selector.SelectionChanging), I am struggling to implement this behavior so I can cancel the changing request.
I tried to handle the TabControl.Items.CurrentChanging
(the Items
property is and ItemCollection
) event setting e.Cancel (of the CurrentChangingEventArgs
) to true, but the UI is is updated with the new tab although the item is not changed in the collection.
Is there any way to prevent user from switching to a different TabItem
when a condition is dissatisfied?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道发生这种情况的确切原因,这让我非常恼火。
但这是我的解决方法:
在下面的示例中,复选框“锁定”当前选项卡。所以选中意味着用户无法更改选项卡。
基本上,发生的情况是(如果我理解正确的话)视觉树得到更新,但逻辑树没有更新。上述方式强制视觉与逻辑树同步。
I don't know the exact reason why this happens, and it annoys me greatly.
But here's my workaround for it:
In the sample below, checkbox is "locking" the current tab. So checked means user can't change tab.
Basically, what happens is (if I understand this correctly) the visual tree gets updated, but the logical tree does not. The above way forces the visual to sync with the logical tree.
您还可以处理每个上的 PreviewLostKeyboardFocus 事件TabItem,并设置事件参数的 Handled 属性为
true 以防止切换到另一个选项卡:
请参阅 http://www.netframeworkdev.com/windows-presentation-foundation-wpf/how-to-cancel-navigation- Between-tabitems-in-a-tabcontrol-84994.shtml 。
You can also handle the PreviewLostKeyboardFocus event on each TabItem, and set the Handled property of the event arguments to
true
to prevent switching to another tab:See http://www.netframeworkdev.com/windows-presentation-foundation-wpf/how-to-cancel-navigation-between-tabitems-in-a-tabcontrol-84994.shtml.