views:

106

answers:

2

I'm creating the "Hello World" demo app for Microsoft Surface. Here's the 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>

Here's the OnCanvasContactDown handler:

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;
}

The problem is that the event handler never gets called. I'm testing it in Visual Studio 2008. The Surface simulator screen appears and when I click it, I get the visual feedback that I "touched" it, but the label never appears. If I put a breakpoint anywhere within the function, it never breaks.

What am I doing wrong?

A: 

Is this something along the lines of OnCanvasContactDown not actually being tied-in as the action delegate handler? There'll be some setup code somewhere (or maybe not - perhaps that's the problem) that sets the handler for the event...

Oh, also the label visibility is set to 'Hidden' - is that a default, or a persistent attribute?

Jonners
+2  A: 

Solved. The problem was that I needed to pre-start the Surface Simulator and set the Build CPU to x86.

elmonty
yes, you can only get Contact events if the app is running inside the surface simulator
Isak Savo
I ran into this one as well. It was very a frustrating experience until I figured out that I need to run the simulator that will start SurfaceInput - little hand icon in your tray area. Also, if you run your app on a real device from VS you will need to make sure that this app is running.
gyurisc