2010-03-19 139 views
0

我正在爲Microsoft Surface創建「Hello World」演示應用。這裏的XAML:Hello World Surface應用不起作用

<s:SurfaceWindow x:Class="HelloWorld.SurfaceWindow1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:s="http://schemas.microsoft.com/surface/2008" 
    Title="HelloWorld" 
    > 
    <s:SurfaceWindow.Resources> 
    <ImageBrush x:Key="WindowBackground" Stretch="None" Opacity="0.6" ImageSource="pack://application:,,,/Resources/WindowBackground.jpg"/> 
    </s:SurfaceWindow.Resources> 

    <Canvas Background="{StaticResource WindowBackground}" s:Contacts.ContactDown="OnCanvasContactDown"> 
     <Label Name="HelloWorldLabel" Visibility="Hidden">Hello, World!</Label> 
    </Canvas> 
</s:SurfaceWindow> 

這裏的OnCanvasContactDown處理程序:

private void OnCanvasContactDown(object sender, ContactEventArgs e) 
{ 
    // Get the position of the current contact. 
    Point contactPosition = e.Contact.GetPosition(this); 

    // Set the X and Y position of HelloWorldLabel 
    // in relation to the canvas. 
    Canvas.SetLeft(HelloWorldLabel, contactPosition.X); 
    Canvas.SetTop(HelloWorldLabel, contactPosition.Y); 

    // Make the label visible. 
    HelloWorldLabel.Visibility = Visibility.Visible; 
} 

的問題是,事件處理程序不會被調用。我正在Visual Studio 2008中進行測試。將出現Surface模擬器屏幕,當我點擊它時,我會看到「觸及」它的視覺反饋,但標籤從不出現。如果我在函數內的任何位置放置斷點,它都不會中斷。

我在做什麼錯?

回答

0

這是什麼沿着OnCanvasContactDown行不是作爲動作委託處理程序實際上綁定?某處會有一些設置代碼(或許不是 - 也許不是 - 也許是這個問題),它爲事件設置處理程序...

哦,標籤可見性也設置爲'隱藏' - 是默認或持久屬性?

2

已解決。問題是我需要預先啓動Surface Simulator並將Build CPU設置爲x86。

+0

是的,如果應用程序在曲面模擬器內運行,則只能獲得聯繫事件 – 2010-03-25 08:27:21

+0

我也遇到了這個問題。這是一個非常令人沮喪的經驗,直到我發現我需要運行模擬器才能啓動SurfaceInput - 您的托盤區域中的小手形圖標。另外,如果您在VS的真實設備上運行應用程序,則需要確保此應用程序正在運行。 – gyurisc 2010-05-05 07:08:03