I have been creating an application in Visual Studio 2015 for Windows Phone 8.1 in the C # language. I have created two pages, Main Page and Page 2. When I am in Page 2 and when I clicked the emulator on the back button, I minimized the application. I added Using windows.phone.ui.input
and this:
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;
using Windows.Phone.UI.Input;
// La plantilla de elemento Página en blanco está documentada en http://go.microsoft.com/fwlink/?LinkID=390556
namespace Cuentos_Infantiles {
/// <summary>
/// Página vacía que se puede usar de forma independiente o a la que se puede navegar dentro de un objeto Frame.
/// </summary>
public sealed partial class BlankPage1 : Page
{
public BlankPage1()
{
this.InitializeComponent();
}
public object NavigationService { get; private set; }
/// <summary>
/// Se invoca cuando esta página se va a mostrar en un objeto Frame.
/// </summary>
/// <param name="e">Datos de evento que describen cómo se llegó a esta página.
/// Este parámetro se usa normalmente para configurar la página.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
Frame.Navigate(typeof(MainPage));
e.Handled = true;
}
private void Contenido1_SelectionChanged(object sender, RoutedEventArgs e)
{
}
}
}
and when debugging again, return to the previous page as I want. But it turns out that being on Main Page (home page), the back button does not respond or minimize or close the application.
This is the Main Page code:
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.Phone.UI;
using Windows.UI.Xaml.Navigation;
// La plantilla de elemento Página en blanco está documentada en http://go.microsoft.com/fwlink/?LinkId=391641
namespace Cuentos_Infantiles
{
/// <summary>
/// Página vacía que se puede usar de forma independiente o a la que se puede navegar dentro de un objeto Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
/// <summary>
/// Se invoca cuando esta página se va a mostrar en un objeto Frame.
/// </summary>
/// <param name="e">Datos de evento que describen cómo se llegó a esta página.
/// Este parámetro se usa normalmente para configurar la página.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: Preparar la página que se va a mostrar aquí.
// TODO: Si la aplicación contiene varias páginas, asegúrese de
// controlar el botón para retroceder del hardware registrándose en el
// evento Windows.Phone.UI.Input.HardwareButtons.BackPressed.
// Si usa NavigationHelper, que se proporciona en algunas plantillas,
// el evento se controla automáticamente.
}
private void Hyperlinkbutton_101_dalmatas_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(BlankPage1));
}
}
}
Please, I need help because I just want to minimize the application like the others by clicking on the back button.
Am I missing some code or what am I doing wrong?