Michael Crump bio photo

Michael Crump


Twitter Google+ LinkedIn Github Youtube Flickr





The User Interface

Very simple just add in the following XAML to the MainPage.xaml :

<!--ContentPanel - place additional content here-->  <Grid x:Name="ContentPanel" Grid.Row="1" Margin="120120">      <TextBlock x:Name="txtName" FontSize="56" Foreground="Red" />  </Grid>


The Code

// Constructor  public MainPage()  {    InitializeComponent();    Touch.FrameReported += new      TouchFrameEventHandler(Touch_FrameReported);  }    void Touch_FrameReported(object sender TouchFrameEventArgs e)  {    TouchPoint mainTouchPoint = e.GetPrimaryTouchPoint(ContentPanel);         Point position = mainTouchPoint.Position;          switch (mainTouchPoint.Action)    {      case TouchAction.Move:        txtName.Text = String.Format("x: {0}  y: {1}"position.X position.Y);        if (position.X == 20 && position.Y == -132) MessageBox.Show("Secret Hit");        break;      case TouchAction.Up:        txtName.Text = "Touch Ended";        break;      case TouchAction.Down:        txtName.Text = "Touch Started";                  break;    }  }

This code is fairly simple as it just adds an event handler for Touch.FrameReported. Inside the method we call GetPrimaryTouchPoint and pass it our ContentPanel (You can of course pass it any UI Element). Now that we have our main touch point we can get the current position the user is touching. The last thing to point out is by calling mainTouchPoint we can see when the TouchAction is Up Down or Moving. Pretty powerful stuff with just a few lines of code.


I ran the application and moved the cursor to the position that I wanted the easter egg to occur in then I added the if…then… statement inside of the TouchAction.Move switch statement.

The Demo




As you can see from this post it really just takes a few lines to get this up and running. It will also work even if the user switches screen orientation.  If you have any questions then feel free to contact me. Also don’t forget to subscribe to my RSS feed and follow me on twitter.