The Year That Stuff Happened.
by DW on Dec.31, 2011, under Electronics, Random, Work
Ok, so it’s the end of the year, and I still haven’t finished building my (rather simple) robot. The current hurdle I’ve not been able to clear involves configuring the XBee Wi-Fi Module. I have tried both the XBee Explorer Dongle and XBee Explorer USB from Sparkfun, without success. I have tested both on multiple machines, and get the same problems.
The X-CTU software used to configure the XBee modules has trouble seeing that the XBee module is connected. I am sometimes able to read the current settings from the XBee, or even write changes to it, but not reliably. It may be something to do with the USB to Serial (RS232) converter that is built in to both boards. Therefore I still haven’t been able to configure in a way that will work how I need it too. If I can’t get it working, I may get the official XBee USB Interface Board from Digi, and try again.
Work, is of course, still work. I go there every day, do what I need to do, and leave as soon as possible. My plan for 2012 is to move on to better things, be that another,more fulfilling job, postgraduate education, or something else. The thought of being stuck in the same hole this time next year is far too depressing. I’m sure all of you will agree, writing ‘software’ using VBA in Microsoft Word and Excel is something no one should have to suffer!
To that end, I’ve been getting involved in more things outside of work, so there is actually something interesting in my life to stop work from finishing me off. I have signed up as a mentor for Young Rewired State, after attending the 2011 Final. I may also look at the other things Rewired State has to offer. I have already met some cool people through there, and we’ve come up with an idea for a project to hack together. I’m not sure I’ll be able to contribute much, as work has killed off most of the useful stuff I once knew, from Uni and before, but it’ll be fun to try.
So it’s onwards into 2012. If 2011 was ‘The Year Stuff Happened’, hopefully 2012 for me will have an equally good tag line. Perhaps ‘The Year I Resurrected my Career’ or ‘The Year I Rose Out of the Gutter’. Either way, if I’m still stuck in the same place this time next year, in the same depressing dead end job, you’ll know I’ve failed. But for now, time to polish my C.V. (if that’s possible), update my website and profiles, and order some Moo cards!
The Forgotten Child(Window): How to Implement Pop-ups on Windows Phone 7.5 Mango – Part 2
by DW on Nov.30, 2011, under App Development, Programming
In my last post, I explain how to get the correct Silverlight assembly referenced in developing a Windows Phone 7.5 application, so you can implement the ChildWindow object. This allows you to add Pop-up dialogue boxes to your application that by default are not possible!
Now, I’m going to show you how to implement the ChildWindow, design your pop-up, and use it in your Windows Phone 7 app. I have tried to keep it simple, and focus on implementing the ChildWindow only. I have not included the other functionality I use in my app. There are many developer resources available that can help you can learn Windows Phone development, such as here at the Windows Phone App Hub, but these resources do not include the ChildWindow class I am explaining here.
First, add a new Windows Phone User Control to your project, and name it, for example ‘Popup.xaml‘. (Right click your project, Click Add -> New Item. Choose Windows Phone User Control from Silverlight for Windows Phone). This will create your control and display the visual and code XAML editors side by side.
You can design your control whichever way you prefer. You may drag controls from the toolbox onto the visual side, or you may type this in the code editor. As it is a pop-up, you should probably keep it simple. I have used just 2 TextBlocks, 1 TextBox and 2 Buttons.
The next step is very important. You must change the XAML to reference ‘System.Windows.Controls‘ and change it from a UserControl to a ChildWindow. It is also important to set the size and position relevant to the screen size. Remember, Windows Phone 7 handsets currently have a 480 x 800 (in portrait) resolution. I have created the pop-up to be 440 wide, not quite the full width of the screen, and only 200 high. (If you were designing your app to work in landscape, you would need to adjust the width and height to be appropriate.) I have positioned it towards the top of the screen, so that the software touch screen keyboard does not cover it. If you have the pop-up too low, it would be behind the keyboard and difficult to use.
Your Popup.xaml code outline should look like this:
<tk:ChildWindow x:Class="ExampleProject.Popup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
VerticalAlignment="Top"
HorizontalAlignment="Center"
Margin="0,40,0,0"
HasCloseButton="false" Height="200" Width="440">
<Grid x:Name="LayoutRoot">
<!--LayoutRoot is the root grid where all page content is placed-->
</Grid>
</tk:ChildWindow>
Next, for any Buttons you have used, make sure the Button Click events have been generated. Now go into ‘Popup.xaml.cs‘, and begin by adding reference to ‘System.Windows.Controls‘ at the top with the line ‘using System.Windows.Controls;‘. Change the base class for your pop-up from ‘UserControl‘ to ‘ChildWindow‘.
The outline of Popup.xaml.cs will now look like this:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace ExampleProject
{
public partial class Popup : ChildWindow
{
public string HostName { get; set; }
public Popup()
{
InitializeComponent();
}
}
}
I am using my pop-up to input a network device Host name, which is then used to set the destination server of a UDP socket when broadcasting data. I have defined that as a public variable in Popup.xaml.cs, so it can be set, and then read back in my main app. I store this as a setting in my app, so it can be saved to memory, and loaded in future. I also have two buttons, ‘OK’ to set the Host name, and ‘Cancel’ to close the Pop-up without doing anything.
I use a Connect button in MainPage.xaml.cs to create an instance of the pop-up and display it. The existing value of Host name is loaded from ‘settings’ and passed to the pop-up window. Important: If you are developing a ‘Silverlight and XNA Application‘, as I am here, you may need to turn off the XNA rendering to display the Pop-up. When I first tried this, my pop-up would not display over the XNA graphics I was rendering at the time.
Opening the Pop-up from MainPage.xaml.cs:
private void btnConnect_Click(object sender, RoutedEventArgs e)
{
// Set the sharing mode of the graphics device to turn off XNA rendering
SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(false);
Popup popup = new Popup();
popup.HostName = settings.HostName;
popup.Closed += new EventHandler(OnPopupShow);
popup.Show();
}
In Popup.xaml.cs, it then takes the current Host name, and puts it into the text box:
protected override void OnOpened()
{
base.OnOpened();
this.txtHostName.Text = this.HostName;
this.txtHostName.SelectAll();
}
Finally the two buttons in Popup.xaml.cs control how it functions in MainPage.xaml.cs:
private void btnOK_Click(object sender, RoutedEventArgs e)
{
// Value is good so close this childwindow
this.HostName = this.txtHostName.Text.Trim();
this.DialogResult = true;
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
}
Back in MainPage.xaml.cs I use the OnPopupShow event that occurs when the pop-up is closed, to decide what to do with the Host name. If the ‘OK’ button was pressed, the pop-up will return ‘true’, and so the Host name entered in the TextBox will be used and saved into the app settings. If ‘Cancel’ was pressed, the pop-up returns ‘false’, and so my application ignores any text that was entered, and will continue to use the existing saved Host name. Important: As we turned off XNA rendering to allow us to display the Pop-up correctly, you can now turn it back on as the Pop-up has closed.
Handling the result of the Pop-up with the OnPopupShow event:
private void OnPopupShow(object sender, EventArgs e)
{
Popup popup = sender as Popup;
if (popup.DialogResult == true)
{
settings.HostName = popup.HostName;
settings.Save();
// Set the sharing mode of the graphics device to turn on XNA rendering
SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true);
}
}
This is a simple implementation of a ChildWindow in a Windows Phone 7 application, used to get the destination Host name for a UDP socket. As I said at the start, I have focussed just on the ChildWindow to display and use a pop-up, and left out the other functionality of my application.
This should now allow you to create your own Pop-up, with whatever controls you need, and use it in your own application. Another application of it could be entering a username and password.
Have fun developing Windows Phone 7 apps – hopefully you will find this useful. If you have any questions, or get stuck, post a comment and I’ll try to help!
The Forgotten Child(Window): How to Implement Pop-ups on Windows Phone 7.5 Mango – Part 1
by DW on Nov.28, 2011, under App Development, Programming
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!










Recent Comments