Just a quick note to say I’ve submitted a book review on Professional Windows Phone 7 Game Development – Creating Games Using XNA Game Studio-4
Uncategorized
What to know if you have a network hub channel clash?
I wanted to diagnose why my wireless hub range was so poor. If you have Windows 7 (or Vista) then you can use the following handy tool;
- Open Command Prompt (e.g. start->cmd)
- in the command windows type, netsh
- wlan
- show networks mode=bssid
Then you can not only you move around and measure the signal strength but also see if there are any other wireless devices using the same channel as your hub.
Keyboard helper for Monotouch
Last year I started developing for Windows Phone 7 and was disappointed by the lack of form support, i.e. if you enter data into a field it you have to write code to move focus into the next field. Whilst developing a solution I stated iOS has much better support. So I was surprised when developing a similar application for iOS that it doesn’t have such support…unless someone can correct me on that?? In fact it’s worse because the keyboard covers the very field you want to type in. So if you want to put controls in a view and have the use move between them AND have them visible, you might find the following code helps. Please note this is very early days for the code so there are some hard coded sizes and probably a few issues, so please let me know if find anything or have a better mechanism. If anyone wants to contribute more formally I might place it on a public code site. Anyway here it is;
public static class KeyboardHelper
{
public static void ScrollControlIntoView(UIScrollView scrollViewer, UIControl field)
{
PointF nextPoint = new PointF(field.Frame.X, field.Frame.Top-30);
scrollViewer.SetContentOffset(nextPoint, true);
}
public static void InitialiseFormFields(UIScrollView scrollViewer, List<UIControl> formFields)
{
System.Diagnostics.Debug.Assert(scrollViewer!=null);
System.Diagnostics.Debug.Assert(formFields!=null);
if (formFields.Count>1)
{
for(int index=0; index< formFields.Count-1; index++)
{
UIControl field = formFields[index];
UITextField textField = field as UITextField;
UIControl nextField = formFields[index+1];
field.EditingDidBegin += delegate(object sender, EventArgs e) {
ScrollControlIntoView(scrollViewer,field);
};
if (textField!=null)
{
textField.ShouldReturn = delegate
{
field.ResignFirstResponder();
if (nextField is IUITextInputTraits)
nextField.BecomeFirstResponder();
KeyboardHelper.ScrollControlIntoView(scrollViewer, nextField);
return true;
};
}
}
}
UIControl lastField = formFields[formFields.Count-1];
UITextField lastTextField = lastField as UITextField;
lastField.EditingDidBegin += delegate(object sender, EventArgs e) {
ScrollControlIntoView(scrollViewer, lastField);
};
if (lastTextField!=null)
{
lastTextField.ShouldReturn = delegate
{
lastField.ResignFirstResponder();
KeyboardHelper.ScrollControlIntoView(scrollViewer, formFields[0]);
return true;
};
}
}
}
To use the helper place your controls in a ScrollView and pass the helper an ordered list of the controls you want it to manage;
formFields = new List<UIControl>() { textBoxName, segmentedGender};
KeyboardHelper.InitialiseFormFields(scrollView, formFields);
Quick aide-mémoire, returning programmatic html in MVC
public ActionResult SayHello()
{
return new ContentResult() { Content = "hello" };
}
Added unit test framework to Windows Phone 7 application
Today I finally decided that I needed a proper unit test framework for my Windows Phone 7 applications, no more hidden links on the start page 😉
I knew I wanted to use Jeff Wilcox’s Silverlight Unit Test Framework but it wasn’t as straight forward as I wanted it to be. Eventually I found this very useful page by Michael Sync. Some of the details and links are a bit old so;
- Download (and remember to unblock) the necessary Dlls from Jeff Wilcox
- The Windows Phone template no longer stores the starting page in the App.xaml, ignore that and instead remove the ‘NavigationPage’ attribute from the ‘DefaultTask’ element in WMAppManifest.xml
Happy Unit Testing…
My .net performance counters were missing on Windows 7
I had a strange problem today. I wanted to take a peek at the CLR memory performance counters but I couldn’t find them. After some searching it turns out I needed to set the following registery key to 0;
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\.NETFramework\Performance\Disable Performance Counters
Wp7 Application Bar, update binding helper
As you may have read I’ve been having ‘fun’ with the Application Bar. Following the really useful post by Laurent Bugnion, I’ve written the following helper that allows you to quickly manage your editable bindable controls. It’s not as simple as I hoped, I’d prefer to be able to get the helper to search for bindable properties but I’ve yet to find a nice way to achieve this – as always I welcome suggestions. Anyway hope this helps;
using System;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Media;
using System.Collections.Generic;
using System.Windows.Data;
namespace pauliom.Helpers
{
public class BindingHelper
{
private BindingHelper(){}
private IEnumerable<BindingExpression> bindables;
public BindingHelper(DependencyObject parent, Type type, DependencyProperty property)
{
bindables = GetChildsRecursive(parent).OfType<FrameworkElement>().
Where(c => c.GetType() == type && c.GetBindingExpression(property) != null).
Select(c => c.GetBindingExpression(property));
}
public void UpdateAllBindings()
{
if (bindables != null)
{
foreach (BindingExpression binding in bindables)
{
binding.UpdateSource();
}
}
}
// code from 'tucod'
IEnumerable<DependencyObject> GetChildsRecursive(DependencyObject root)
{
List<DependencyObject> elts = new List<DependencyObject>();
elts.Add(root);
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
elts.AddRange(GetChildsRecursive(VisualTreeHelper.GetChild(root, i)));
return elts;
}
}
}
So to use the code you create helper per type of control and property you want to keep updated;
private BindingHelper bindingForGridTextBoxes;
void Page_Loaded(object sender, RoutedEventArgs e)
{
this.bindingForGridTextBoxes =
new BindingHelper(LayoutRoot, typeof(TextBox), TextBox.TextProperty);
this.DataContext = viewModel;
}
then whereever you need to ensure the bindings are up-to-date, e.g. when one of the cheeky non-framework Application Bar buttons are clicked;
this.bindingForGridTextBoxes.UpdateAllBindings();
wp7 Keyboard helper as a behavior
Thanks to a number of comments regarding the problems I had with the ApplicationBar and the keyboard I’ve decided to apply some of the ideas to my previous post (thanks everyone for the comments) about a keyboard helper to create a self contained keyboard tab helper behavior (mouthful). I’ve posted the full code and binaries, Wp7KeyboardSource.zip
but essentially all you now have to do is;
<Grid x:Name=“ContentGrid“ Grid.Row=“1“>
<i:Interaction.Behaviors>
<keyboard:KeyboardTabHelperBehavior />
</i:Interaction.Behaviors>
<StackPanel Orientation=“Vertical“>
<CheckBox IsTabStop=“True“ TabIndex=“4“ Content=“Some check“/>
<TextBox TabIndex=“1“ Text=“start here“/>
<TextBox IsTabStop=“True“ Text=“Won’t tab here cause not set tabindex“/>
<TextBox IsEnabled=“False“ TabIndex=“2“ Text=“not here cause disabled“/>
<TextBox TabIndex=“3“ Text=“next stop here“/>
</StackPanel>
</Grid>
…and that’s it, no code behind, no adding of event handlers. Just set up your tab index and stops and it will take care of the rest.
Changing Blog
I’m trying WordPress now, let’s see how it goes
Hello world!
Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!