我正在尝试使用 Visual Studio 2013 Express 中的通用应用程序为桌面/平板电脑和手机创建 Windows 应用商店应用程序。我在理解 WPF 中发生的事情时遇到了一些困难,因为我之前的 Windows 8 开发经验是使用 HTML/JS 应用程序。
我让VS创建一个新项目->Visual C#->Store Apps->Universal Apps->Blank App。我打开 MainPage.xaml.cs 并在构造函数的第一行放置一个断点,恰好是 this.InitializeComponent()。我按下 F5,应用程序编译,然后我切换到熟悉的全屏 Modern 应用程序视图,但没有一个断点被击中。
我在 MainPage.xaml 中添加了一个 TextBlock,以便其中有一些东西,但仍然没有命中断点。我错过了什么?下面是(一些)由 Visual Studio 生成的代码。我可能错过了关于 WPF 应用程序如何工作和结构化的一些非常基本的东西,但是我所有的 google-fu 都化为乌有。
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.
}
}
}