0

我正在为 Microsoft Surface 创建“Hello World”演示应用程序。这是 XAML:

<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 模拟器屏幕出现,当我单击它时,我得到了我“触摸”它的视觉反馈,但标签从未出现。如果我在函数中的任何位置放置断点,它永远不会中断。

我究竟做错了什么?

4

2 回答 2

2

解决了。问题是我需要预先启动 Surface Simulator 并将 Build CPU 设置为 x86。

于 2010-03-19T17:42:43.800 回答
0

这是否类似于OnCanvasContactDown实际上并没有被绑定为动作委托处理程序?某处会有一些设置代码(或者可能没有 - 也许这就是问题所在)为事件设置处理程序......

哦,标签可见性也设置为“隐藏” - 这是默认属性还是持久属性?

于 2010-03-19T16:13:12.173 回答