简体   繁体   中英

Event to detect when user clicks/taps outside a control

I have a StackPanel, which contains a ListBox. The StackPanel appears when the user selects a particular option. I want the StackPanel to disappear when the user taps/clicks anywhere outside the panel. Can anyone suggest how this can be achieved?

I think that if you just tap outside the panel, LostFocus won't work. If you select another control, however, it might. Therefore I think you should check if the panel is the currently focused one, on the main form outside of that panel, and then do whatever you wanted to do.

(Haven't worked with windows 8 metro apps, so I don't know the names or what's possible, but this is how I would do it in WinForms if the first try didn't work)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM