User (Old forums)MemberAugust 14, 2007 at 7:22 amPost count: 23064
I am trying to hive off my resources into a resource dictionary and of course as recommended you shouldn;t be putting events into the Resource. Instead, the Event Handling should be written up in C# code behind.
OK…So, simply I have a resource which is a ContextMenu…
<MenuItem Header=”_Remove Record”/>
<MenuItem Header=”_Add Record”/>
and its referred to in a Style for a DataRow….Note there is no Click EVent mentioned in the ContextMenu.
So, I need to trap when one of the Menu Items is clicked. I thought that by just registering an Event it would work…
EventManager.RegisterClassHandler( typeof(ContextMenu), ContextMenu.MouseDownEvent, new RoutedEventHandler(OnContextMenuMouseDown));
However, nothing happens when the Mouse goes down in the Context Menu i.e. it is not getting to the code at ‘OnContextMenuMouseDown’ – It compile OK so I know the Event args are OK…
Imported from legacy forums. Posted by Desmond (had 965 views)User (Old forums)MemberAugust 14, 2007 at 7:33 amPost count: 23064
Oh…just an added item….as I was typing this I tried the following which did indeed work…AND in a Resource Dictionary…which was I suppose the main aim…
EventManager.RegisterClassHandler(typeof(MenuItem), MenuItem.MouseDownEvent, new RoutedEventHandler(OnMenuItemMouseDown));
So I can proceed…might be worth checking though that it is not my code that is wrong in the ContextMenu event handling…
Imported from legacy forums. Posted by Desmond (had 429 views)User (Old forums)MemberAugust 14, 2007 at 8:39 amPost count: 23064
It may be that the MouseDownEvent is already “handled”, so try registering handler against the PreviewMouseDownEvent, which is ..
The tunneling event that will be “first raised at the root and then on each element down the visual tree until the source element is reached (or until a handler halts the tunneling by marking the event as handled).” – Reference p.66 Adam Nathan’s WPF Unleashed (Sams Books)
Imported from legacy forums. Posted by Richard (had 333 views)User (Old forums)MemberAugust 14, 2007 at 11:41 amPost count: 23064
Bang on NBN!! Appreciate it…
Yes the PreviewMouseDownEvent does indeed trap the event (not that the other wasn’t but as you say tennelling!).
Seems a tad confusing I must admit…but at least I know (or rather – we all know) what are the ‘possibilities’ of some of these events firing real shots or firing subliminal tracers.
Imported from legacy forums. Posted by Desmond (had 506 views)User (Old forums)MemberAugust 20, 2007 at 10:02 amPost count: 23064
Without starting a new thread….
How do you suspend the events in a calling screen from firing in the situation when you call a sub-screen and the same event is being trapped or even limit the scope of the event.
e.g. I have the following code in each screen…but the calling screen’s routine gets called when I am in the Dialog ?
EventManager.RegisterClassHandler(typeof(Cell), Cell.KeyDownEvent, new KeyEventHandler(this.OnCellKeyDown));
Any ideas ?
Imported from legacy forums. Posted by Desmond (had 4561 views)
- You must be logged in to reply to this topic.