Mouse left button up and openfiledialog

I have several images in the grid, then when I click the button, the "open file" dialog box appears (of course, by image).

Microsoft.Win32.OpenFileDialog dlgOpenFiles = new Microsoft.Win32.OpenFileDialog (); dlgOpenFile.DoModal ();

Images have an attached LeftButtonUp event. The problem is that if I select the file by double-clicking it, the file open dialog closes (which is good), but in addition, the image receives a LeftButtonUp message, which is not very good.

I am using wpf / c # / vs2010

+3
source share
1 answer

An easy way to get around this is when you need a handler for an event with buttons, add an event with a button down, do CaptureMouse() in it. Now in your event with buttons, you can ignore all events that occur without IsMouseCaptured . And don't forget ReleaseMouseCapture() :

 private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { CaptureMouse(); } private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (!IsMouseCaptured) return; ReleaseMouseCapture(); var dlg = new OpenFileDialog(); var res = dlg.ShowDialog(this); // ... } 
+4
source

Source: https://habr.com/ru/post/1307934/


All Articles