ModernTab link as button

Jul 9, 2013 at 10:41 AM
When using a ModernTab layout, is it possible to make clicking a link run some other code rather than navigate to a new page?
Jul 10, 2013 at 12:49 AM
Edited Jul 10, 2013 at 12:51 AM
I'll take a crack at this, probably wrong.

First write a command. I use VB sorry, here's my example:
Imports FirstFloor.ModernUI.Presentation
Imports FirstFloor.ModernUI.Windows.Controls

Public Class ShaveMyBeard
    Inherits CommandBase

    Protected Overrides Sub OnExecute(parameter As Object)
        Select Case CStr(parameter)
            Case "smooth"
                ModernDialog.ShowMessage("Smooth", "Shave", MessageBoxButton.OK)
            Case "rough"
                ModernDialog.ShowMessage("Rough", "Shave", MessageBoxButton.OK)
        End Select
    End Sub
End Class

On your XAML page ensure there's an app reference:
xmlns:app="clr-namespace:WpfApplication11"

Add resources for the commands you want to execute:
        <Grid.Resources>
            <!-- define an implicit BBCodeBlock style and add custom commands to the link navigator -->
            <Style TargetType="mui:BBCodeBlock" >
                <Setter Property="LinkNavigator">
                    <Setter.Value>
                        <mui:DefaultLinkNavigator>
                            <mui:DefaultLinkNavigator.Commands>
                                <app:ShaveMyBeard x:Key="shave://beard" />
                            </mui:DefaultLinkNavigator.Commands>
                        </mui:DefaultLinkNavigator>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>
What's important here is that the key you use here, must match your URL in the BBCode.

Here's example BBcode:
[url=shave://beard|rough]rough[/url] or [url=shave://beard|smooth]smooth[/url]
my url shave://beard matches the key, the parameter is what lets me use a single command for multiple things.