Technology

Windows Phone 7-Shake It Like You Mean It!

Anthony Marshall
Anthony Marshall
24 Feb 2011
blog post featured image
<h3>Shake Gesture Library Now Available</h3> <p>&#160;</p> <p><a href="http://techstudio-website-alt.azurewebsites.net/Content/blog/uploads/2011/02/image-thumb27.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px 10px 10px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb27" border="0" alt="image_thumb27" align="left" src="http://techstudio-website-alt.azurewebsites.net/Content/blog/uploads/2011/02/image-thumb27-thumb.png" width="225" height="240" /></a>When developing applications for Windows Phone 7 you have access to vast amounts of information about the device through its sensors. One of these is the accelerometer&#160; which can give you information on where the device is moving within 3D space, this can be utilised in many different ways, the most prominent of these being in gaming. </p> <p>There are however many other ways to use this information, you may want a user to be able to shake their device to update their&#160; twitter list instead of pressing a button, or many other implementations like this.</p> <p>To make this easier to do you can now use the Shake Gesture Library which is available to download from the <a href="http://create.msdn.com/downloads/?id=714" target="_blank">AppHub</a>&#160; and there is also a great overview on the <a href="http://windowsteamblog.com/windows_phone/b/wpdev/" target="_blank">Windows Phone Developer Team Blog</a>.</p> <p>&#160;</p> <h3>The Magic Eight Ball App</h3> <p>&#160;</p> <p>To show how easy this is to use, lets write a simple app, I want to&#160; ask my eight ball a question, shake my device and have an answer appear.</p> <ul> <li><font face="Arial">Create a new Windows Phone 7 project in Visual Studio:</font></li> </ul> <p><a href="http://techstudio-website-alt.azurewebsites.net/Content/blog/uploads/2011/02/newproj.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="NewProj" border="0" alt="NewProj" src="http://techstudio-website-alt.azurewebsites.net/Content/blog/uploads/2011/02/newproj-thumb.jpg" width="510" height="341" /></a></p> <ul> <li>Create a UI which has an image of an eight ball with a TextBlock hovering over the top to show the answer.</li> </ul> <p>&#160;<a href="http://techstudio-website-alt.azurewebsites.net/Content/blog/uploads/2011/02/magiceightball-microsoft-visual-studio-administrator.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="MagicEightBall - Microsoft Visual Studio (Administrator)" border="0" alt="MagicEightBall - Microsoft Visual Studio (Administrator)" src="http://techstudio-website-alt.azurewebsites.net/Content/blog/uploads/2011/02/magiceightball-microsoft-visual-studio-administrator-thumb.jpg" width="510" height="139" /></a></p> <ul> <li>Add initialisation of a<em> List&lt;string&gt;</em> to hold our responses</li> </ul> <p><a href="http://techstudio-website-alt.azurewebsites.net/Content/blog/uploads/2011/02/magiceightball-microsoft-visual-studio-administrator-2.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="MagicEightBall - Microsoft Visual Studio (Administrator) (2)" border="0" alt="MagicEightBall - Microsoft Visual Studio (Administrator) (2)" src="http://techstudio-website-alt.azurewebsites.net/Content/blog/uploads/2011/02/magiceightball-microsoft-visual-studio-administrator-2-thumb.jpg" width="510" height="116" /></a></p> <ul> <li>In the Loaded event of our page add the handling for the shake gesture using the Shake Gesture Library.</li> </ul> <p><a href="http://techstudio-website-alt.azurewebsites.net/Content/blog/uploads/2011/02/mainpage.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="MainPage" border="0" alt="MainPage" src="http://techstudio-website-alt.azurewebsites.net/Content/blog/uploads/2011/02/mainpage-thumb.jpg" width="510" height="188" /></a></p> <p>&#160;</p> <p>That’s our App done, your Windows Phone 7 can now impart you with the knowledge of the Universe. Go Shake!!</p> <p><a href="http://cid-756a9b00ae9a5e3b.office.live.com/self.aspx/Windows%20Phone%207/MagicEightBall.7z" target="_blank">Download the sample</a></p>
Close chatbot
Open chatbot
Open chatbot