routed-events

Custom attached events in WPF

余生颓废 提交于 2019-12-07 17:32:23
问题 I might be getting the terminology wrong here, but I think I'm trying to create an attached event. In the Surface SDK, you can do things like: <Grid Background="{StaticResource WindowBackground}" x:Name="Foo" s:SurfaceFrameworkElement.ContactChanged="Foo_ContactChanged"/> I want to create a custom event for which a handler can be added in XAML in the same way, but I'm having trouble. I can create a custom routed event, but the XAML intellisense doesn't see it and the event handler isn't added

Custom attached events in WPF

依然范特西╮ 提交于 2019-12-06 03:32:18
I might be getting the terminology wrong here, but I think I'm trying to create an attached event. In the Surface SDK, you can do things like: <Grid Background="{StaticResource WindowBackground}" x:Name="Foo" s:SurfaceFrameworkElement.ContactChanged="Foo_ContactChanged"/> I want to create a custom event for which a handler can be added in XAML in the same way, but I'm having trouble. I can create a custom routed event, but the XAML intellisense doesn't see it and the event handler isn't added if I just type it in regularly. Here is my event definition: public static class TagRectEvents {

Programmatically Call WPF TargetedTriggerAction

邮差的信 提交于 2019-12-05 15:09:49
I have a TargetedTriggerAction from a 3rd party library that would like to call/invoke without attaching it to a button. I have no problem getting it to work with the button, but I want to do it in response to some non-UI event. Here is the action's class declaration: public class MeasureAction : TargetedTriggerAction<Map> Here is my setup code so far: var measure = new MeasureAction(); measure.TargetObject = _mapControl; measure.MeasureMode = MeasureAction.Mode.Polyline; measure.MapUnits = DistanceUnit.Miles; I want to be able to do something like this, but I know Invoke is protected: measure

The correct way to do a tunneled event

浪尽此生 提交于 2019-12-05 01:49:13
问题 EDIT : I guess I asked a bit of a XY Problem. I don't really care about getting tunneled events working, what I care about is getting a event raised from the code behind of the parent window to be picked up and reacted to by a control that is a child of that window without explicitly needing to tell the child who its parent is and manually subscribing to the event. I am trying to raise a event in a parent control and having the child controls listen for that event and react to it. From my

Checking if a RoutedEvent has any handlers

≯℡__Kan透↙ 提交于 2019-12-03 20:20:51
I've got a custom Button class, that always performs the same action when it gets clicked (opening a specific window). I'm adding a Click event that can be assigned in the button's XAML, like a regular button. When it gets clicked, I want to execute the Click event handler if one has been assigned, otherwise I want to execute the default action. The problem is that there's apparently no way to check if any handlers have been added to an event. I thought a null check on the event would do it: if (Click == null) { DefaultClickAction(); } else { RaiseEvent(new RoutedEventArgs(ClickEvent, this));;

The correct way to do a tunneled event

感情迁移 提交于 2019-12-03 16:43:24
EDIT : I guess I asked a bit of a XY Problem. I don't really care about getting tunneled events working, what I care about is getting a event raised from the code behind of the parent window to be picked up and reacted to by a control that is a child of that window without explicitly needing to tell the child who its parent is and manually subscribing to the event. I am trying to raise a event in a parent control and having the child controls listen for that event and react to it. From my research I thought I just needed to do a RoutedEvent but I am doing something incorrect. Here is a MCVE

MouseDoubleClick events don't bubble

与世无争的帅哥 提交于 2019-12-03 11:19:28
问题 My scenario, simplified: I have a ListView containing rows of Employees, and in each Employee row, there are buttons "Increase" and "Decrease" adjusting his salary. Pretend that in my program, double-clicking an Employee row means "fire this person". The problem is that while I'm clicking "Increase" rapidly, this triggers a double click event on the ListViewItem. Naturally, I don't want to fire people when I'm just increasing their salary. According to how all other events work, I expect to

Is there a way to watch WPF Routed Events?

醉酒当歌 提交于 2019-12-03 07:28:13
问题 I was wondering if there's a way to watch all RoutedEvents that are raised in a WPF application. A way to write some info about the events fired to the console would be prefect to see what's going on. 回答1: Yes, but it requires some reflection. You're better off using a tool like Snoop that already does the hard lifting for you. In the tab Events you can see list of events, and the element that handled it. 回答2: I've found another way: I've added this to the loaded handler of my UserControl.

MouseDoubleClick events don't bubble

你。 提交于 2019-12-03 01:40:16
My scenario, simplified: I have a ListView containing rows of Employees, and in each Employee row, there are buttons "Increase" and "Decrease" adjusting his salary. Pretend that in my program, double-clicking an Employee row means "fire this person". The problem is that while I'm clicking "Increase" rapidly, this triggers a double click event on the ListViewItem. Naturally, I don't want to fire people when I'm just increasing their salary. According to how all other events work, I expect to be able to solve this by setting Handled=true on the event. This, however, doesn't work. It appears to

Is there a way to watch WPF Routed Events?

◇◆丶佛笑我妖孽 提交于 2019-12-02 20:58:50
I was wondering if there's a way to watch all RoutedEvents that are raised in a WPF application. A way to write some info about the events fired to the console would be prefect to see what's going on. Kent Boogaart Yes, but it requires some reflection. You're better off using a tool like Snoop that already does the hard lifting for you. In the tab Events you can see list of events, and the element that handled it. I've found another way: I've added this to the loaded handler of my UserControl. var events = EventManager.GetRoutedEvents(); foreach (var routedEvent in events) { EventManager