Domanda

I am trying to create a Windows Store app for Desktop/tablet and Phone with a Universal App in Visual Studio 2013 Express. I am having some difficulty understanding what is happening in WPF, as my prior Windows 8 development experience has been with HTML/JS apps.

I ask VS to create a New Project->Visual C#->Store Apps->Universal Apps->Blank App. I open MainPage.xaml.cs and put a breakpoint on the first line in the constructor function, which happens to be this.InitializeComponent(). I hit F5, the app compiles and I am switched to the familiar full-screen Modern app view, but none of my breakpoints are ever hit.

I add a TextBlock to MainPage.xaml just so that there's something in there, but still no breakpoints are hit. What am I missing? Below is (some) the code the is generated by Visual Studio. I am probably missing something very fundamental about how WPF apps work and are structured, but all my google-fu has come to naught.

MainPage.xaml:

<Page
    x:Class="SoloCoach.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SoloCoach"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>

    </Grid>
</Page>

MainPage.xaml.cs:

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 Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace SoloCoach
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();

            this.NavigationCacheMode = NavigationCacheMode.Required;
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // TODO: Prepare page for display here.

            // TODO: If your application contains multiple pages, ensure that you are
            // handling the hardware Back button by registering for the
            // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
            // If you are using the NavigationHelper provided by some templates,
            // this event is handled for you.
        }
    }
}
È stato utile?

Soluzione

When you create a Universal App it creates both a Windows 8.1 and a Windows Phone 8.1 app. The code you're showing is the default page constructor for the Phone version so you're probably in the wrong project which is not the Windows Modern App that you're running.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top