2014-04-19 30 views
0

我正嘗試使用Visual Studio 2013 Express中的通用應用程序爲桌面/平板電腦和手機創建Windows應用商店應用。我很難理解WPF中發生的事情,因爲我之前的Windows 8開發經驗是HTML/JS應用程序。爲什麼不調用我的WPF頁面控件的構造函數?

我問VS創建一個新項目 - > Visual C# - >商店應用程序 - >通用應用程序 - >空白應用程序。我打開MainPage.xaml.cs並在構造函數的第一行放置一個斷點,這恰好是this.InitializeComponent()。我打F5,應用程序編譯,我切換到熟悉的全屏現代應用程序視圖,但我的斷點都沒有擊中。

我爲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. 
     } 
    } 
} 

回答

1

當您創建它創建一個通用的應用程序都在Windows 8.1和Windows Phone的8.1應用程序。您顯示的代碼是電話版本的默認頁面構造函數,因此您可能位於錯誤的項目中,而該項目不是您正在運行的Windows現代應用程序。

+0

婊子的兒子。我無法相信我忽略了這一點。我希望我可以放棄你的所有代表並退出本網站。 Stackoverflow seppuku。 –

相關問題