Tip: Breadcrumb navigation outside the Breadcrumb control

Navigation for WPF Forum

Posted 16 years ago by Joseph Gershgorin
Version: 4.0.0457
Avatar
I wanted back and forward functionality in the Breadcrumb control, this can by provided by ActionButtons. The problem with ActionButtons is that they only visually exist inside the Breadcrumb control. I wanted back/forward buttons similiar to Windows Vista's back/forward button, and visually they are outside the Breadcrumb.

Even though Actipro Breadcrumb ActionButtons use commands, the commands aren't exposed publically. To not have to re-invent the back/foward logic for my own buttons, I tied into existing functionality using the following method.

I created a couple of ActionButtons, and set their visibility to collpased so they're not visible, like this:

<actipronavigation:Breadcrumb.ActionButtons>
     <Button Visibility="Collapsed" x:Name="NextPageActionButton" Command="NavigationCommands.NextPage" />

     <Button Visibility="Collapsed" x:Name="PreviousPageActionButton" Command="NavigationCommands.PreviousPage" />

</actipronavigation:Breadcrumb.ActionButtons>
Then I created a couple of buttons outside the BreadCrumb and databound the enabled/disabled state to the ActionButton's enabled/disable state, like this:

<Button                        
    x:Name="btnNavigatePrevious"        
        IsEnabled="{Binding ElementName=PreviousPageActionButton, Path=IsEnabled}"
        Click="btnNavigatePrevious_Click"
>

<Button 
    x:Name="btnNavigateNext"        
        Click="btnNavigateNext_Click"                                            
    IsEnabled="{Binding ElementName=NextPageActionButton, Path=IsEnabled}"
/>
Finally, in the code behind for click event for the newly crated buttons, using UI automation I click the appropriate collapsed ActionButton, like this:

private void btnNavigateNext_Click(object sender, RoutedEventArgs e)
{
    ClickAButton(NextPageActionButton);
}

private void btnNavigatePrevious_Click(object sender, RoutedEventArgs e)
{
    ClickAButton(PreviousPageActionButton);
}

private static void ClickAButton(Button ButtonSource)
{
    ButtonAutomationPeer peer = new ButtonAutomationPeer(ButtonSource);

    IInvokeProvider invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
    
    invokeProv.Invoke();
}
Of course a better solution would be if Actipro exposed the ActionButton commands, but for now this solution works, so I thought I'd share in case someone else would like similar functionality.

Comments (5)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello Joseph,

The Breadcrumb reuses the NavigationCommands, which is available under the System.Windows.Input namespace. These are part of WPF and are publicly exposed.

The Action Buttons QuickStarts shows how these are used. But let us know if it still doesn't make sense.


Actipro Software Support

Posted 16 years ago by Joseph Gershgorin
Avatar
Yes, the Breadcrumb uses the standard built-in NavigationCommand names.

However, when I try calling the command by clicking on a button which exists outside the Breadcrumb control, but in the same window, with the same assigned "command" property, then nothing (no action on the Breadcrumb) happens.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Can you post the XAML code for you button?

Since the button is not contained within the Breadcrumb control you would need to set the CommandTarget on the Button so that the command is forwarded to the Breadcrumb control.


Actipro Software Support

Posted 16 years ago by Joseph Gershgorin
Avatar
Yep, you're right, thanks, looks like my syntax was off. Here is what ended up working:

<Button Command="NavigationCommands.NextPage"
        CommandTarget="{Binding ElementName=ControlPanelBreadcrumb}" />
("ControlPanelBreadcrumb" is the X:Name of the Breadcrumb Control)
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I'm glad we could help.


Actipro Software Support

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.