Can't get attached Message firing

Feb 12, 2011 at 2:39 PM


Maybe i am stupid, but i can't get an Action Message working in one specific case. Probably it has something to do with the particular control i am trying to attach to.

I am using the great WPF trayicon library from Philipp Sumi (

I try to show a view on double click on the tray icon. The tray view control (TaskbarIcon) is derived from FrameworkElement and supports a couple of routed events, one of them TrayMouseDoubleClick.

The tray icon is the root shell of the application, so i have overriden the standard Caliburn WindowManager to create a TrayIconViewModel for the root model. This works fine. The corresponding TrayIconView looks like this:

<UserControl x:Class="ServerGui.Views.TrayIconView"
<tb:TaskbarIcon ToolTipText="Reg.Net Server running on XP/2003"
cal:Message.Attach="[Event TrayMouseDoubleClick] = [Action ShowAbout()]"
IconSource="{Binding TrayIcon}">
<Views:TrayBalloonView />
<Views:TrayPopupView />
<MenuItem Header="Show Console"
cal:Message.Attach="ShowConsole()" />
<MenuItem Header="About Reg.Net Server"
cal:Message.Attach="ShowAbout()" />
<Separator />
<MenuItem Header="Exit"
cal:Message.Attach="ExitProgram()" />

The Context Menu actions work fine. The double click action on the TaskbarIcon itself not.

I checked that the RoutedEvent "TrayMouseDoubleClick" is fired correctly by adding some code to the code-behind of TrayIconView:


        public TrayIconView()
foreach (RoutedEvent routedEvent in EventManager.GetRoutedEvents())
new RoutedEventHandler(AllEventsLogger));

static void AllEventsLogger(object sender, RoutedEventArgs routedEventArgs)


Here is the output in the debugger console window when i double-click the tray icon:




I can't figure out why it doesn't work. Any help on this is really appreciated.




Feb 12, 2011 at 2:39 PM

By the way, i have had a hard time trying to figure out why it doesn't work.

Inside the Caliburn Micro code everything seems to be ok, i stepped through Message.OnAttachChanged. I also enabled all WPF trace settings.

But there is no hint at all why the EventTrigger isn't get triggered by TrayMouseDoubleClick.

Does anyone have some hints how to debug this?




Feb 12, 2011 at 3:23 PM

Check to make sure that TrayMouseDoubleClick is actually an EventHandler and not something like Action<T>. The EventTrigger only seams to work with events that follow the standard pattern. If that turns out to be the problem, you would need to define a custom trigger or contact the control author and ask him to redefine the event following the standard pattern. This is just a guess, but I saw something like this happen once before with the EventTrigger. To tell for sure if it is happening in the trigger, you can put break points in the ActionMessage OnAttach and Invoke methods. If OnAttach is called, but Invoke is not called, then it'sprobably an issue with the trigger itself.

Feb 12, 2011 at 3:45 PM

Here is the definition:

    /// <summary>
    /// TrayMouseDoubleClick Routed Event
    /// </summary>
    public static readonly RoutedEvent TrayMouseDoubleClickEvent = EventManager.RegisterRoutedEvent("TrayMouseDoubleClick",
        RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon));

    /// <summary>
    /// Occurs when the user double-clicks the taskbar icon.
    /// </summary>
    public event RoutedEventHandler TrayMouseDoubleClick
      add { AddHandler(TrayMouseDoubleClickEvent, value); }
      remove { RemoveHandler(TrayMouseDoubleClickEvent, value); }

So TrayMouseDoubleClick is an RoutedEventHandler. That seems to be pretty much the standard implementation of a routed event handler.

OnAttached() gets called for the double click action, MethodName and AssociatedObject looks good.

But Invoke() doesn't get called.

I traced through OnAttached and noticed a possible problem. IsLoaded was false on the view so an event handler was attached (AssociatedObject.Loaded += ElementLoaded).

ElementLoaded though never got called. That is probably a problem of the implementation of TaskbarIcon. I have to look for a workaround it seems.

Thanks for the hints, they pointed me to the right spot :).




Feb 12, 2011 at 4:24 PM
Edited Feb 13, 2011 at 9:33 AM

I modified the TaskbarIcon class a bit and added:


          Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(
() => RaiseEvent(new RoutedEventArgs(LoadedEvent))));


just after the tray icon was created in the constructor


ElementLoaded gets called now, but still no Invoke()

Feb 13, 2011 at 9:32 AM

I couldn't get it to work so i now just rely on the good old (ugly :)) ICommand interface of TaskbarIcon which it also provides.



Mar 9, 2011 at 6:03 PM

Can you, please, post your sample? Thanks

Mar 9, 2011 at 6:53 PM

Which sample? Do you use TaskbarIcon? My problem is a TaskbarIcon specific problem.

Mar 31, 2011 at 10:08 PM

FYI: just posted an article with the solution -