Home Forums WPF controls Xceed DataGrid for WPF ContextMenu and EventManager.RegisterClassHandler

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24202 |

    Hi,
    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…

    <pre>
    <ContextMenu x:Key=”Standard_ContextMenu”>
    <MenuItem Header=”_Remove Record”/>
    <MenuItem Header=”_Add Record”/>
    </ContextMenu>
    </pre>

    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…

    <pre>
    EventManager.RegisterClassHandler( typeof(ContextMenu), ContextMenu.MouseDownEvent, new RoutedEventHandler(OnContextMenuMouseDown));
    </pre>

    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…

    Stumped !…

    ANy ideas…

    Cheers,

    Dezzz.

    Imported from legacy forums. Posted by Desmond (had 965 views)

    User (Old forums)
    Member
    Post 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…

    <pre>
    EventManager.RegisterClassHandler(typeof(MenuItem), MenuItem.MouseDownEvent, new RoutedEventHandler(OnMenuItemMouseDown));
    </pre>
    <hr>
    So I can proceed…might be worth checking though that it is not my code that is wrong in the ContextMenu event handling…

    Cheers,

    Dezzz.

    Imported from legacy forums. Posted by Desmond (had 429 views)

    User (Old forums)
    Member
    Post 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)

    http://msdn2.microsoft.com/en-us/library/ms742806.aspx

    Imported from legacy forums. Posted by Richard (had 333 views)

    User (Old forums)
    Member
    Post 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.

    Cheers,

    Dezzz.

    Imported from legacy forums. Posted by Desmond (had 506 views)

    User (Old forums)
    Member
    Post 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 ?

    <pre>
    EventManager.RegisterClassHandler(typeof(Cell), Cell.KeyDownEvent, new KeyEventHandler(this.OnCellKeyDown));
    </pre>

    Any ideas ?

    Dezzz.

    Imported from legacy forums. Posted by Desmond (had 4561 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.