Search code examples
wpfxamlnavigationframe

Frame Navigation without code-behind


I am trying to create a navigation-application using Ribbon buttons (or regular buttons). When I try the following code (namespace definitions omitted)

<Window ...>
    <StackPanel>
        <Button Command="NavigationCommands.GoToPage" CommandParameter="/Pages/Welcome.xaml" CommandTarget="{Binding ElementName=MainFrame}">Click</Button>
    <Frame x:Name="MainFrame"></Frame>
    </StackPanel>
</Window>

the button grayed out and doesn't work. Is there anyway possible to achieve this without using code-behind or any framework?


Solution

  • Is there anyway possible to achieve this without using code-behind or any framework?

    No, I don't think so, apparently only DocumentViewer and FlowDocumentPageViewer (but not Frame) support NavigationCommands.GoToPage natively: https://social.msdn.microsoft.com/Forums/vstudio/en-US/1ff0906f-3847-46fe-8aff-c121e9caf655/how-to-enable-a-navigationcommandsgotopage-command?forum=wpf