Sajeev C
Sajeev C

Reputation: 1538

Unable to navigate to another page on button click in windows phone 8.1

I have a button & upon clicking it, I need to go to another xaml page.

This button resides in Page1.xaml

<Button Content="Button Name" HorizontalAlignment="Center" VerticalAlignment="Center" Click="Button_Click" Foreground="#FF119FF0"/>


    private void Button_Click(object sender, RoutedEventArgs e)
    {
       frameBody.Navigate(typeof(HomePage)); 
    }

But I am not able to navigate to HomePage.xaml.

What can be the reason??

These are the libraries I included:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

The function Button_Click() is defined in Page1.xaml.cs.

Upvotes: 0

Views: 1668

Answers (4)

Waheed Rafiq
Waheed Rafiq

Reputation: 482

Another most important point to notice is you might want to check 'App.xaml.cs' file and within OnLaunched method change the

   rootFrame.Navigate(typeof(UrPage),e.Arguments);

by default MainPage.xaml loads.

Upvotes: 0

Benjamin Diele
Benjamin Diele

Reputation: 1187

This is the code that I use in my project:

    private void ItemView_ItemClick(object sender, ItemClickEventArgs e)
    {
        var albumId = ((Album)e.ClickedItem).Id;
        if (!Frame.Navigate(typeof(AlbumPage), albumId))
        {
            var resourceLoader = ResourceLoader.GetForCurrentView("Resources");
            throw new Exception(resourceLoader.GetString("NavigationFailedExceptionMessage"));
        }
    }

The part to focus on is Frame.Navigate(typeof(AlbumPage)).

I want to pass some information to that page, that's why I pass my albumId.

If you want to retrieve the passed argument in your other page, you might want to use this code:

    private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
    {
        var albumId = (int)e.NavigationParameter;
    }

Upvotes: 1

Ajinkya Jeurkar
Ajinkya Jeurkar

Reputation: 78

Check if you are using a windows phone sliverlight project and your class is extending/inheriting "PhoneApplicationPage" like this :

public partial class Example : PhoneApplicationPage
{
        private void Button_Click(object sender, RoutedEventArgs e)
        {    
            NavigationService.Navigate(new Uri("/Homepage.xaml", UriKind.RelativeOrAbsolute));   
        }  
}

Hope this helps

Upvotes: 2

Abdul Samad Khan
Abdul Samad Khan

Reputation: 102

I think You are missing a directive or an assembly reference?

for window phone 8.1 navigation

 Frame.Navigate(typeof(Urpage));

for window phone 8.0

        NavigationService.Navigate(new Uri("/URpage.xaml", UriKind.Relative));

Upvotes: 2

Related Questions