Link navigation with BBCodeBlock to local folder

Sep 12, 2014 at 10:13 AM
Hello,

I would like to use a BBCodeBlock to let user navigate to a local folder. I tried to use something like:

[url=file:///C:/Users] open folder[/url]

or

[url=C:/Users] open folder[/url]

But the error I get when I click on the link created is:

Unable to navigate to file:///C:/Users, could not find a ModernFrame taget ''

Any ideas on how to do that?

Thank you,

Igor
Sep 15, 2014 at 3:30 PM
I haven't been able to get a folder to open by using the file:// protocol, but I instead made my BBCode have a link with a command that when executed, will open up the folder or exe.

xaml:
<mui:BBCodeBlock Grid.Row="1"
                         Margin="0,2,0,0"
                         BBCode="[url=cmd://openFile|pathToFileOrFolder]click here[/url]}"
                         Foreground="{DynamicResource WindowTextReadOnly}"
                         LinkNavigator="{Binding LinkNavigator}" />
view model:
OpenReportCommand = new RelayCommand<string>(s => ExecuteOpenReport(s));
LinkNavigator = new DefaultLinkNavigator();
LinkNavigator.Commands.Add(new Uri("cmd://openFile", UriKind.Absolute), OpenReportCommand);

public RelayCommand<string> OpenReportCommand { get; private set; }
private void ExecuteOpenReport(string r)
{
    try
    {
         Process.Start(r);
    }

    catch (Exception ex)
    {
        logger.Warn("unable to open " + r, ex);
    }
}
Sep 15, 2014 at 4:29 PM
Hello,

How can I find references for types OpenReportCommand, RelayCommand, LinkNavigator and so on.

My project does not find any namespaces for these types.

Thank you,

Igor.
Sep 16, 2014 at 1:11 AM
So I'm following the MVVM pattern and using mvvmlight's implementation of ICommand called RelayCommand. But MUI does provide one too (also called RelayCommand) - you need to use the proper namespace:
using FirstFloor.ModernUI.Presentation;
and for the LinkNavigator, use
FirstFloor.ModernUI.Windows.Navigation
I think you need to read the MUI documentation and perhaps some on the MVVM pattern. Check the demo application source too - its a great resource.
Coordinator
Sep 19, 2014 at 3:07 PM
In order to support file:// navigation in BBCodeBlock you'll need to register the file scheme as external scheme in the link navigator. By default the DefaultLinkNavigator supports http, https and mailto. Adding file support is as easy as defining the following:
<mui:BBCodeBlock BBCode="[url=file:///C:/Users]open folder[/url] ">
  <mui:BBCodeBlock.LinkNavigator>
    <mui:DefaultLinkNavigator>
      <mui:DefaultLinkNavigator.ExternalSchemes>
        <x:Array Type="sys:String" xmlns:sys="clr-namespace:System;assembly=mscorlib">
          <sys:String>http</sys:String>
          <sys:String>https</sys:String>
          <sys:String>file</sys:String>
        </x:Array>
      </mui:DefaultLinkNavigator.ExternalSchemes>
    </mui:DefaultLinkNavigator>
  </mui:BBCodeBlock.LinkNavigator>
</mui:BBCodeBlock>
You can move this to a default BBCodeBlock style, so the LinkNavigator is shared with all BBCodeBlock instances.