Menu
  • HOME
  • TAGS

How are UI events generated in WPF?

c#,wpf,events,routed-events,uievent

Eventually it must be WM_MOUSEFIRST and similar Windows events that trigger actions in WPF. No doubt. That is how Windows works. Inside WPF, it uses EventManager and GlobalEventManager to handle events. A Window and all subsequent base classes registers itself at the EventManager (like Window and FrameworkElement here). The EventManager...

Why is there no MouseMoveEvent — or, how to use AddHandler for the mouse move event

c#,.net,silverlight,mouseevent,routed-events

It is explicitly mentioned in the MSDN article: MouseMove cannot be used with AddHandler because there is no Handled in its event data So that answers your questions: Why is there no MouseMoveEvent defined anywhere? Because none is needed. Is there a workaround that allows you to get a notification...

How to cancel a left mouseclick on button release (Preview…Up)

wpf,wpf-controls,routed-events

I modified the OnPreviewMouseLeftButtonUp Method and manage to fixed this behavior. The wrong event handler is called because the button is still in focus. if you move the focus back to the main window it should work as expected: protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e) { base.OnPreviewMouseLeftButtonUp(e); if (isDragging && dragMoveCount...

How do I bubble an event from a user control up to window it is contained in?

c#,wpf,xaml,routed-events

Button.Click is already bubbling event so you don't need Button_Click in your UserControl. All you need to do is attach handler in you Window, Grid or ViewBox <Grid Button.Click="ButtonHandler"> and in the handler check e.OriginalSource instead of e.Source var fe = e.OriginalSource as FrameworkElement; and it should work...

Why WPF ListBox.ListItems do not raise MouseRightButtonDown

c#,wpf,xaml,routed-events

It says right in the book why the listbox does not work for right click "Window never receives the MouseRightButtonDown event when you right-click on either ListBoxItem. That's because ListBoxItem internally handles this event as well as the MouseLeftButtonDown event (halting the bubbling) to implement item selection" Link to page...

Can I communicate from child viewmodels to main window with a routed command or routed event?

wpf,mvvm,routed-events,routed-commands

You can setup a static class that can just be an Action, and handle registrations for any subscribers. Whoever is subscribed to that command can invoke the action. The idea is something like this.. public static class CommandManager { List<ViewModel> _subscribers; static CommandManager() { _subscribers = new List<ViewModel>(); ShowDialogCommand =...

Same click event for both Button and Grid

wpf,button,grid,routed-events

Button.Click event is routed event with bubbling strategy set to Bubble. That means it will bubble up to visual parent till root until it was handled. In your case, you raise an event from Window, so it will bubble up from Window to its parent which is null. You have...

WPF routedevent storyboard begin only if height is zero

wpf,storyboard,wpf-controls,routed-events

You may use a DoubleAnimation instead of an ObjectAnimationUsingKeyFrames. By only setting its To property, but not From, the animation starts from the current property value. It requires that you also set an initial value of the Height of the Border: <Border Height="20" ...> <Border.Triggers> <EventTrigger RoutedEvent="MouseLeftButtonUp"> <BeginStoryboard> <Storyboard> <DoubleAnimation...