[Caliburn Micro] How to bind the HyperLink of click event in Caliburn.Micro

Topics: Actions & Coroutines, Bugs, Extensibility, UI Architecture
Aug 20, 2011 at 8:36 AM


I would like to bind the Hyperlink controls Click event through Caliburn.Micro?

Aug 20, 2011 at 1:19 PM

you could do it 2 ways... 1 using System.Windows.Interaction and use ActionMethod in CM + a Parameter (If necessary) or you can do this

cal:Message.Attach = "[Event Click] = [Action MethodName]"  where methodname is your public void in your viewmodel.




Feb 17, 2012 at 12:51 PM

I've just tried the second option and I get an exception:

System.InvalidOperationException: Cannot attach type "ActionMessage" to type "Hyperlink". Instances of type "ActionMessage" can only be attached to objects of type "FrameworkElement".

Do you know what documentation do I need to look at for the first option you suggested?

Many thanks in advance.

Feb 17, 2012 at 2:11 PM

The ActionMessage mechanism only works with FrameworkElements. Can I assume you are using WPF? I believe that in Silverlight, the Hyperlink is a FE, but in WPF it is not. Out of all the Xaml platforms only WPF sometimes implements controls as FrameworkContentElement instead of FrameworkElement (it doesn't exist in SL, WP7 or WinRT). Unfortunately, supporting both possibilities, solely for WPF, would greatly increase the complexity of Caliburn.Micro. This is mostly due to the fact that Microsoft (after my repeated requests) has failed to implement a common interface between the two base classes, which would make generic programming possible...in fact, it would greatly simplify and likely improve the perf of WPF's internals as well. As things stand, we are stuck without a good solution.

As a workaround, you can create a custom behavior to attach to your hyperlink which internally calls the ActionMessage pipeline using Action.Invoke.

Nov 27, 2012 at 3:37 PM

I have found an easy workaround in this StackOverflow question and I have adapted it to Caliburn.Micro and it is working.

Hope it Helps: