DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Adding an Easter Egg to your WP7 Application

Adding an Easter Egg to your WP7 Application

Michael Crump user avatar by
Michael Crump
·
Dec. 27, 11 · Mobile Zone · Interview
Like (0)
Save
Tweet
3.69K Views

Join the DZone community and get the full member experience.

Join For Free

i was asked the other day how to detect if a user has touched a certain part of the screen. i created some sample code for them but decided that it might make a fun easter egg as well.  it does this by comparing the x and y axis of the users current touch point to the location that the “m” exists. basically, this application will detect if your user is touching the letter m as shown below.

image

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="12,0,12,0">
    <textblock x:name="txtname" fontsize="56" foreground="red" />
</grid>

i’ve added a textblock just to show you the current x and y coordinates that the user has touched. it will also show you when the user has started and stop touching the device.

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.

so how did you know the x and y positions of the letter “m”?

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

here you will see a demo of what this project accomplishes. you can download the source code as well.

wp7easteregg

wrap-up

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 .


source: http://michaelcrump.net/adding-an-easter-egg-to-your-wp7-application

application EGG (file format)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Getting Started With RSocket Kotlin
  • How to Manage a Red Hat MicroShift Cluster with Shipa
  • 7 Tips for Using Instrumentation and Metrics To Align Site Reliability With Business Goals
  • Internal Developer Platform in Plain English

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo