Grid row double click performs action on main window - wpf

This issue regarding WPF window (XAML application)
I have a two windows one window getting launced from another window.
Both window get into maximized state when gets open
the child window which gets open has a grid on it and we have operation (double click on row click should close the window).
Problem is happening that when we double click on grid row it closes form correctly but if accidently mouse remains in the same position then some operation on previous window gets perform. if mouse point in different location then there is no problem.
I am not able to define this as event bubbling in WPF or routed events.
Could you please advise on this.

I think you should add:
e.Handled = true

Related

Why doesn't ResizeBegin get called for a maximized MDIChild?

In Winforms if the MDI child window is maximized it doesn't receive ResizeBegin (or ResizeEnd) events. It does receive Resize events - why the distinction? If the child isn't maximized it does get ResizeBegin/End events. Is there a nice way around this? There are plenty of ugly ways: calling directly from the MDI container ResizeBegin event to the child for example.
The ResizeBegin/End events are generated when the user starts and stops resizing a window. Implemented by a modal loop inside Windows itself, it keeps the window edge following the mouse cursor when the user moves it. ResizeBegin when he clicks a window edge, ResizeEnd when he releases the mouse button.
Clearly no user is involved when you change the Size or ClientSize property of an MDI child window in your code. So no Begin or End, just the Resize event. And just one Resize event trigger, there's no constant train of them like there will be when the user uses the mouse to resize. Which otherwise explains why Begin/End is important, if you do a lot of work in your Resize event handler then you'll bog down the UI pretty heavily. Common with automatic layout, the visible artifacts are not pretty.
If you really have to then you can simply generate the event yourself. Call OnResizeBegin() before, OnResizeEnd() after you change the window's Client/Size property value. That code needs to live inside the window you resize to get the correct event triggered. Pretty unlikely you should be doing this btw. Do beware that MDI automatically resizes an maximized MDI child window, it of course cannot be maximized anymore when you activate another one. You can't wrap that with OnResizeBegin/End() calls.

Closing a WPF window when responding to doubleclick transfers doubleclick to the main window

I have seen similar issues reported but never answered. This is a major problem for me.
I have a WPF application which opens a new window using ShowDialog(). In the new Window I have a datagrid but it could be any type of object. When I handle the doubleclick event of a row I close the window. At this point the window closes but the control in the main window directly under where I clicked recieves the clicks.
I tried handling PreviewMouseButtonDown and looking for clickcount=2 instead of the doubleclick but that had the same effect. I tried setting e.Handled = true and that also had the same effect. I tried setting an owner on the window and no change. I tried modal as well as regular windows and no change. I responded to the PreviewMouseButtonDown for a single click and that worked but I absolutely need this to be a double click.
Problem is double-click event fires on 2nd mouse DOWN event. If you close the window as part of that event-handling, you're still about to receive a mouse UP event in whatever window was open behind the dialog.
I think the solution might be to set a flag during double-click handling and on mouse up, if the flag is set, close the window.
Ok, i had a similiar problem in our project and its somehow related. We never really fixed it, but now i gave it some more thoughts. And my guess is, because you close the window while you are in a progress of handling the input, this input processing is canceled, your window is closed, but the input request it still remains (because it was not handled before) thus your parent window gets to handle it.
So this is of course just a shot in the dark but would explain our problem.
So to give a solution:
You could instead of close the window, set up a Dispatcher Job using lower priority as Input and just close the window there. It should feel the same for the user but should consume the double click.
Again no guaranty it just sounds resonable in my head.
Good luck.

ComboBox doesn't raise keyboard and mouse events as expected

I use Silverlight 4.0 and have got problems with ComboBox control. I want to implement a popup menu which will show and hide itself without clicking mouse. It should show when I place cursor on its region - this prt works well. Then it should hide whenever mouse pointer is placed outside of its region for a while. I implemented it with MouseEnter and MouseLeave events. My problem is ComboBox - this control behaves weirdly, in my opinion. Normally I would expect it to raise MouseEnter event when I put the cursor on it and MouseLeave when I put the mouse cursor anywhere else. The real situation is different: Whenever I click the combobox, it opens and shows the list of options, and immediately sends LostFocus and MouseLeave events. So it seems like the control lost keyboard focus and mouse pointer has been moved out of its region, while actually the combobox list of optins is open and active and has keyboard focus in it.
So the question is how can I know in my program what is happening in comboboxes? In order to correctly hide my popup menu, I need to know when the list of options in a combobox is open or closed. I can't see any events for this or any other documentation. (Wanted behavior is: If a combobox is closed, I hide my popup menu based on the position of mouse cursor. If a combobox is open, I never hide my popup menu until user either selects something in the combobox, or closes the combobox.)
Also, if you have got a good experience with a third party combobox replacement, which looks and works similarly AND raises events I need, please let me know.
MSDN has two events listed for ComboBox that you might want to look at.
http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox_events(v=VS.95).aspx
DropDownClosed Occurs when the drop-down portion of the combo box closes.
DropDownOpened Occurs when the drop-down portion of the combo box opens.

Silverlight: Modal ChildWindow keeps parent grayed after closing

When my modal ChildWindow closes, the parent control does not get "un-grayed" and all user input is blocked, forcing me to restart the application. Exact scenario which causes this behavior consistently:
ChildWindow A pops up and user clicks a custom button on the bottom of the window (instead of OK or Cancel). My code does some work and then calls the Close() method for the ChildWindow.
ChildWindow A closes and functionality is restored to parent control (controls are un-grayed).
User causes ChildWindow B to pop up. User clicks system-generated OK or Cancel button.
ChildWindow B closes, but the parent controls are still grayed out and inaccessible.
Either of the windows work fine repeatedly on their own. Any thoughts?
I saw something similar (it might not fix your exact problem) and found some discussion about the ChildWindow here
they suggested this method in the ChildWindow Closed event and it worked for me.
Application.Current.RootVisual.SetValue(Control.IsEnabledProperty, true);
Also try calling this.DialogResult = true instead of the Close method.

WPF Mouse behavior when ComboBox is focused

When the WPF ComboBox is clicked and in-focus, the only interaction that occurs after that can be with the ComboBox. If anything else is interacted with, including the window functions (minimize, restore, close, resize) and any control in the window, the action is ignored and the ComboBox loses focus.
In addition, MouseEnter and MouseLeave on the window buttons are still active, but when MouseEnter on the window border(?) occurs, the mouse pointer does not change to the resize pointer. This behavior makes sense because of the ComboBox's use of the popup control. The popup control exists independently of the main visual tree and if i.e. the window moves or gets resized, the popup remains fixed floating above the main window.
I have tried using Reflector, to see what the ComboBox is doing, but I have not been able to find what I am looking for. Basically, I do not know if this behavior is coming from the window, the ComboBox, or if it has something to do with the popup. How can I solve this problem?
You're right on in your description there, the popup keeps all action focus until it itself loses focus. If you're trying to change the functionality of the ComboBox you may want to look at creating your own ControlTemplate that behaves differently and does not keep the default action of the popup control.
Hope this helps, not entirely sure what you're trying to do.
I know this question is old, but for anyone coming here looking for the answer, it is to use Mouse.Capture.
The ComboBox sets Mouse.Capture(comboBox, CaptureMode.SubTree) in OnIsDropDownOpenChanged. This ensures that all mouse events are captured by the ComboBox. When the Popup is closed Mouse.Capture(null) releases the mouse capture.

Resources