In the comparatively basic Windows Phone 7 app I am currently writing, I wanted to do something I thought would be simple. It should be simple. To have a dialog box pop-up and allow me to input data into a text box. This could be useful to get a username and password, for example, without navigating to a completely different ‘page’ in the app. Or it could just be to pop-up and display information messages in a different place on the screen, rather than across the top using a ‘MessageBox’.
I could not just use a ‘MessageBox’ because I need to add at least a TextBox control on to the pop-up. I’ve done this in other software I have written, and those have only been basic applications at best, written in C# (or even at work, the dreaded, depressing VBA!). But for some reason, for Windows Phone 7, this has been made very difficult!
Silverlight includes exactly the object needed – the ChildWindow. But although Silverlight for Windows Phone includes the System.Windows.Controls namespace, where ChildWindow is found, that particular feature is absent from the phone version.
Instead, to be able to implement a ChildWindow in a Windows Phone 7 application, you must manually reference the full System.Windows.Controls.dll in your project, from the main Silverlight SDK. (Right Click ‘References’, Click ‘Add Reference’, Click ‘Browse’, then locate and select System.Windows.Controls.dll). On my machine it was found here: “C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\System.Windows.Controls.dll” (Please check your machine – the Silverlight SDK may be installed in a different location.)
If you do not have the Silverlight SDK installed, please download it here: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=18149
This includes the Silverlight 4.0 SDK, and will configure it for use in Visual Studio 2010.
Once you have the correct reference, you are ready to add a Pop-up (ChildWindow) to your Windows Phone 7 application! If you are familiar with using the ChildWindow from other Silverlight development, you’re sorted.
If not, stay tuned for my next post which will explain specifically how to use this and get a Pop-up dialog box in a Windows Phone 7 application!