Bind a BBCodeBlock's command to a property in the page's ViewModel?

Apr 6, 2013 at 6:57 PM
Like I can with a button, is it possible to be able to bind a BBCodeBlock's command to a property (ICommand) in the page's ViewModel?

I don't quite get how I can do this with the DefaultLinkNavigator?

I simply want to launch a command via a link.

Apr 7, 2013 at 3:50 PM
Edited Apr 8, 2013 at 9:03 PM
Yes, you can define a CommandDictionary as a property on your viewmodel and bind it to the DefaultLinkNavigator.Commands.
public class MyViewModel
  public MyViewModel()
    this.LinkNavigator = new DefaultLinkNavigator();
      new Uri("cmd://mycustomcommand", UriKind.Absolute), this.MyCommand);
  public ILinkNavigator LinkNavigator {get;set;}
  public ICommand MyCommand {get;set;}
You can then use the following BBCode to use the command;
  LinkNavigator="{Binding LinkNavigator}"
  BBCode="Click [url=cmd://mycustomcommand]here[/url] to execute cmd." />
See also this tutorial on commanding and BBCodeBlock.

For another example see the Navigation.xaml page in the demo app (in the source at 1.0\FirstFloor.ModernUI\FirstFloor.ModernUI.App\Pages
Apr 8, 2013 at 4:29 PM
Edited Apr 8, 2013 at 5:05 PM
I get the following error when I try to set the Commands property of the DefaultLinkNavigator:

A 'Binding' cannot be set on the 'Commands' property of type 'DefaultLinkNavigator'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject

Any ideas?

In the mean time, I have accessed my Page's VM in codebehind and set the myBBCodeBlock.LinkNavigator.Commands to myVM.Commands and this works.
Apr 8, 2013 at 9:03 PM
Edited Apr 8, 2013 at 9:04 PM
My bad, I didn't test the snippet..

Anyway, updated the original answer, see above. DefaultLinkNavigator is not a dependency object and cannot be used as binding target.