imran
imran

Reputation: 59

All navigation in a single page

I am new in Windows 8 apps using XAML and C#.
I want all navigation in a single page and I have created a button in main page and then create a second page. When user click on button from main page it 2nd page must show in main page.
How can I do this?

Main page xaml :

<Button Content="click" FontSize="60" Margin="191,283,0,382" Height="103" 
Click="Button_Click" ></Button>

Main page:

private void Button_Click(object sender, RoutedEventArgs e)
{            
    this.Frame.Navigate(typeof(Page1),"p");
}

page 1:

<TextBlock FontSize="59" SelectionChanged="TextBlock_SelectionChanged">
    hi  2nd page is open
</TextBlock>

When user clicks on button the second page should be shown in main page.

Upvotes: 1

Views: 117

Answers (1)

Muhammad Umar
Muhammad Umar

Reputation: 3781

You have to use Frame inside your main page. Try this

MainPage.xaml

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="227*"/>
        <ColumnDefinition Width="1139*"/>
    </Grid.ColumnDefinitions>
    <Button Name="firstPageButton" Content="First Page" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="53" Width="227" Click="firstPageButton_Click"/>

    <Frame Name="rootFrame" Content="" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="1" Height="758" Width="1129"/>

</Grid>

MainPage.xaml.cs

private void firstPageButton_Click(object sender, RoutedEventArgs e)
{
    rootFrame.Navigate(typeof(Page1),"p");    
}

Note: When ever you add page in metro apps, just keep in mind that you always add Split Page from Visual Studio Template instead of Blank Page because Split Page contains some default built in functionality like Title, Back Button,GoBack() etc.

Upvotes: 2

Related Questions