routed-events

Routed events and dependency properties .NET wrapper confusion

时光总嘲笑我的痴心妄想 提交于 2019-12-02 13:50:17
问题 I'm new to WPF and have a confusion about wrapping syntax of routed events and dependency properties I've seen on many sources that routed events and dependency properties are wrapped like this // Routed Event public event RoutedEventHandler Click { add { base.AddHandler(ButtonBase.ClickEvent, value); } remove { base.RemoveHandler(ButtonBase.ClickEvent, value); } } // Dependency Property public Thickness Margin { set { SetValue(MarginProperty, value); } get { return (Thickness)GetValue

Why is the TextBlock not the OriginalSource on the Routed Event?

纵饮孤独 提交于 2019-12-02 02:29:23
I'm showing a context menu for elements in a ListView . The context menu is attached to the TextBlock s of the ListView as follows. <ListView.Resources> <ContextMenu x:Key="ItemContextMenu"> <MenuItem Command="local:MyCommands.Test" /> </ContextMenu> <Style TargetType="{x:Type TextBlock}" > <Setter Property="ContextMenu" Value="{StaticResource ItemContextMenu}" /> </Style> </ListView.Resources> The context menu properly shows up and the RoutedUIEvent is fired as well. The issue is that in the Executed callback the ExecutedRoutedEventArgs.OriginalSource is a ListViewItem and not the TextBlock.

Understanding Routing Events: Why I need both, bubble and tunnel events?

旧巷老猫 提交于 2019-12-01 19:15:57
I read this good article about Routed Events, and I understood why we need sometimes bubble Events and sometime we need tunnel Events. What I didn't understand is, when we use the tunnel Event, why after it is handled or reached to the source element, still the bubble event is launched? Thanks in advance! The article says that if you put an image on a button, and that image is clicked, the tunnel event for that image will fire. But it is highly likely that you would also want to handle that click as if the button itself was clicked, so a bubble event is also fired which bubbles up to the click

RoutedEventArgs vs EventArgs

三世轮回 提交于 2019-11-29 06:13:52
问题 I am learning WPF / Silverlight and saw in an MS vidcast that it is now recommended to use RoutedEventArgs over EventArgs ; although it didn't say exactly why. I have a win forms app that uses interfaces for "widgets" in an attempt to not be tied to a specific display technology (in Presenters / ViewModels), so if my IButton Click event now needs to take the RoutedEventArgs now I guess it isn't as useful. Can someone please explain if I should switch to RoutedEventArgs in all cases and why?

Why e.Handled = true not working?

你说的曾经没有我的故事 提交于 2019-11-29 03:59:19
I have following XAML <StackPanel MouseEnter="StackPanel_MouseEnter" Height="130" Background="Blue"> <Grid MouseEnter="Grid_MouseEnter" Height="60" Background="Red" > <Button MouseEnter="Button_MouseEnter" Height="20"/> </Grid> </StackPanel> In code behind I am doing this private void StackPanel_MouseEnter(object sender, MouseEventArgs e) { } private void Grid_MouseEnter(object sender, MouseEventArgs e) { e.Handled = true; } private void Button_MouseEnter(object sender, MouseEventArgs e) { e.Handled = true; } Now even if I move mouse over Button and set e.Handled = true , the events of Grid

using attached events with caliburn micro Message.Attach

故事扮演 提交于 2019-11-27 20:42:34
I'm trying to use caliburn micro message to trigger an attached event that I created: public static class DataChanging { public delegate void DataChangingEventHandler(object sender, DataChangingEventArgs e); public static readonly RoutedEvent ChangingEvent = EventManager.RegisterRoutedEvent("Changing", RoutingStrategy.Bubble, typeof(DataChangingEventHandler), typeof(DataChanging)); public static void AddChangingHandler(DependencyObject o, DataChangingEventHandler handler) { ((UIElement)o).AddHandler(DataChanging.ChangingEvent, handler); } public static void RemoveChangingHandler

using attached events with caliburn micro Message.Attach

梦想与她 提交于 2019-11-26 20:25:57
问题 I'm trying to use caliburn micro message to trigger an attached event that I created: public static class DataChanging { public delegate void DataChangingEventHandler(object sender, DataChangingEventArgs e); public static readonly RoutedEvent ChangingEvent = EventManager.RegisterRoutedEvent("Changing", RoutingStrategy.Bubble, typeof(DataChangingEventHandler), typeof(DataChanging)); public static void AddChangingHandler(DependencyObject o, DataChangingEventHandler handler) { ((UIElement)o)