Navigate to another page on button click

Codeone picture Codeone · Nov 15, 2015 · Viewed 16k times · Source

I am developed the Windows mobile application I've added the button for VS blend 2015 , but there's no button navigate to option how to bind to my button for the page sub.xaml

<Button x:Name="button" Content="Enter" Height="42" Margin="122,-113,0,0" 
     VerticalAlignment="Top" Width="144" Foreground="#FF50CBC5" 
     Background="#FF0F0E0E" HorizontalAlignment="Left"/>

Answer

user3956566 picture user3956566 · Nov 22, 2015

The hyperlink button gives you the option to navigate to another page onclick.

This screen shot is from Blend.

enter image description here

So change your mark up as follows, including the generated Click handler.

<HyperlinkButton x:Name="button" Click="HyperlinkButton_Click"
    Content="Enter" Height="42" Margin="122,-113,0,0" 
    VerticalAlignment="Top" Width="144" Foreground="#FF50CBC5" 
    Background="#FF0F0E0E" HorizontalAlignment="Left"/>

Then in your cs, you need to direct the navigation.

// Button to navigate to sub.xaml page.
private void HyperlinkButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
    // Navigate back to sub.xaml page.
    this.Frame.Navigate(typeof(SubPage));
}