I have this situation:
<Button MouseDown="Button_MouseDown" Click="Button_Click">
<TextBlock MouseDown="Inner_MouseDown">Button</TextBlock>
</Button>
Method Inner_MouseDown is completely empty. .Handled is NOT set to true.
But Button_Click is not executed. If I remove the MouseDown="Inner_MouseDown",button clicks without problems. Can anybody help me find out why handling MouseDown with no logic prevents button from click?
Thanks a lot.
Andrej
OK, I found out something important. It seems that it works good until I add breakpoint to Inner_MouseDown method. If debugger stops there Click event is not raised. If I just remove the breakpoint it works allright. Same problem if I show messagebox in the Inner_MouseDown method. If I just increment some temp variable it works nice.
But this answers my question, why it does not work even if it should. Actually it works, problem is somewhere else.
My guess: It may be because Click == MouseDown + MouseUp within a small time interval, and when you break after the MouseDown, the MouseUp isn't processed until after the time interval has elapsed.
Related
I am working on a windows store application and I want to be able to drag between buttons so that the originally pressed button becomes deactivated and the newly "dragged onto" button becomes activated but I can't seem to get this to work.
I have 2 Buttons inside a StackPanel and the events I have on them are:
PointerPressed
PointerEntered
PointerReleased
PointerExited
PointerCanceled
PointerCaptureLost
PointerPressed and PointerEntered share the same event handler and the rest (the "deactivation" events) share the same event handler.
If I press one button my "activated" event handler is triggered and if I drag off it my "deactivated" event handler is triggered but if I then drag onto the second button the "activated" event handler isn't triggered again.
Strangely, if I start by dragging from off the StackPanel onto one of the buttons the "activated" event handler is triggered. I assume that it is something to do with the internal pointer management stuff but can't seem to find a workaround.
Does anyone know why this is happening and how I can get it to work how I want?
Thanks for your time.
Edit
Okay I've been researching some stuff and I've come across CapturePointer() and ReleasePointerCapture() but this seems to be broken - If I capture the pointer, when I take my finger off the screen, PointerReleased doesn't even get hit.
I've also realized why the "dragging from off the SP onto one of the buttons causes it to 'activate'" - this is because when a button is pressed it doesn't route its event but fires a Click event - meaning the same pointer cannot fire a PointerEntered event of another button, but if it starts outside a Button it will trigger PointerEntered.
This doesn't get me much further but it is a little extra info :)
The concept of Button is a bit unique in regard to mouse capture and how dragging away from it happens. In your scenario I'm not sure if the event model around Button will work correctly for you. On Button, when a pointer is depressed (mouse) it has capture until it is released. This is not the same for touch where a press and drag away is different because in touch there isn't any explicit capture unless you create it.
So what you are hitting is going to be a slight conflict between mouse/touch interactions anyway using Button -- using some other UI element (not sure if you have a styled button) should get you what you want.
Does anyone know if you can find out if the print dialog's cancel was clicked?
I've seen post and doc that say "EndPrint – Event fired when the printing is either completed or canceled. "
But I don't think that is the print dialog's canceled... I think the is if the print job is canceled.
thanks
Based on the documentation, I don't believe there's an easy way:
http://msdn.microsoft.com/en-us/library/system.windows.printing.printdocument.endprint(v=VS.95).aspx
In particular:
The EndPrint event will not occur if
the user cancels the print operation
from the print dialog box. A
BeginPrint event will always occur
before an EndPrint event.
Apparently the EndPrint event is only to clean up in the case of the document actually printing, not in the case of canceling the print dialog.
There is one way,
if the 'PrintPage' event is not CALLED after you call 'printDocument.Print()' method that means 'Cancel' button was pressed by the user on print dialog.
hope it helps.
I cant get mouseleave to fire inside a ribboncombobox inside a ribboncontrolgroup inside ribbon tab inside a ribbon.
I have a behavior that on mouse enter opens the dropdown and should close it on mouseleave
except mouseleave doesnt fire I verified this using snoop and by setting a breakpoint on the event.
Any ideas or workarounds?
I was having a similiar issue with the border control - and I found an event called, "IsMouseDirectlyOverChanged" - that seemed to fire pretty regularily so I used that.
In my surface application I have a SurfaceWindow with a SurfaceUserControl on. On the SurfaceUserControl I have a SurfaceButton but the ContactUp (and down) event is not fired. The ContactHoldGesture event is fired though.
Any ideas?
Could you include some code to reproduce? Where are you subscribing to those events?
Most likely what's happening is the contact up and down events are being handled by the button, so they don't fire at the usercontrol level. Try looking at the previewcontactup and previewcontactdown events.
ContactUp and ContactDown are handled by the button itself - that's why the events never get to your code. If you really want to intercept these events, use PreviewContactUp/PreviewContactDown instead. What you probably really need though is to just handle the Click event on the button. Adjust the ClickMode property of the button if you want to change what causes the Click event to be raised.
I have a button which launches a "modal dialog" - it just creates a transparent grid covering everything, with the "dialog" created on top of that.
However I have a strange issue - if I double/triple click the button really fast (or add some delay in the event code), the button click event is executed multiple times, creating multiple overlapping modal dialogs. If the first action in my event is to disable the button (IsEnabled=false) it seems to prevent this.
My guess is that Silverlight is being multithreaded with input - it is not only recording the second click in another thread (while the button's click event is running), but it is jumping the gun by evaluating which control should be the target before the previous event has finished executing. Even though that event alters what control is at those mouse coordinates, it doesn't matter.
Does anyone know anything about this behavoir, or a way around it? If I have something like a save window, where the user clicks a save button, a blocking grid ("Saving...") is placed up while it saves, and then the whole "window" is closed, I'd like to avoid the user being able to queue up multiple save event clicks (this could lead to unpredictable program behavoir).
If you've ever worked with WinForms or WPF, this is expected behavior. Your button is broadcasting its Click event until your modal dialog covers it up. Unfortunately, there is some amount of time between your first click and when the modal dialog covers the button which allows multiple clicks to the original button.
You have two solution choices:
Disable the button after the first click and then re-enable after the modal dialog returns. You've already mentioned that this works.
Write code in the Event Handler of the button to determine if a modal dialog is already being displayed. This way, you're putting the responsibility in one location rather than splitting it up (disabling and re-enabling the button). This would be my preferred solution.
I think what you're seeing is the behaviour of Silverlight's routed events.
You can set the Handled property of the event arguments to true to prevent the event from bubbling.