WPF在出现MessageBox时停止路由事件? [英] Wpf stop routing event when MessageBox appear?

查看:200
本文介绍了WPF在出现MessageBox时停止路由事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在TreeView上具有PreviewMouseDown事件,以便确定用户是否可以基于某种逻辑选择其他项. 如果当前项目数据已更改,将出现MessageBox,询问用户是否要放弃更改.如果用户按YES,则将e.Handled = false;设置为启用新选择.如果用户按NO,则将e.Handled = true;设置为取消新选择.

I've PreviewMouseDown event on TreeView in order to determine if user can select other item based on some logic. If the current item data changed, will appear MessageBox that asks the user if he want to discard the changes. if user press YES , I set e.Handled = false; to enable the new selection. and if user press NO, I set e.Handled = true; to cancel the new selection.

问题是,尽管我设置了e.Handled = false,但事件停止并且TreeView上没有发生选择事件.有人对此有解决方案吗?

The problem is that although I set e.Handled = false , the event stop and no selection event occurs on TreeView. Someone has solution for that?

提前谢谢!

推荐答案

将焦点更改为消息框将取消鼠标按下事件,因此无论是否处理该事件都无关紧要.因为在显示消息框之前您已经知道用户试图选择哪个项目,所以只要用户按YES,就可以通过编程方式选择该项目.

The focus change to the message box cancels the mouse down event so it doesn't matter whether it is handled or not. Since you know which item the user was trying to select before you displayed the message box, simply select that item programmatically if the user presses YES.

这篇关于WPF在出现MessageBox时停止路由事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆