Archive for October, 2010

Windows Phone 7 – No “editable” TextBlock

October 16, 2010 5:11 pm

As I’m diving into Windows Phone 7 development and making notes for myself on how WP7 compares to WebOS, I’ve come across one little wrinkle that works really nicely in WebOS (out-of-the-box) and doesn’t work so well in WP7 (out-of-the-box).

I’m talking about a control (actually, a Widget in WebOS) that initially looks like a regular text label, but when you tap on it, it turns into a text box that lets you edit the contained text. WP7 does not have anything like this out-of-the-box. So I decided to create my own.

I made a UserControl that consists of a TextBlock and a TextBox. The TextBox is normally Collapsed (Hidden doesn’t exist on WP7, you’d have to use Opacity=”0″ instead). When the user taps on the TextBlock, it is collapsed and the TextBox is made visible. Once the TextBox loses focus, the reverse happens, and the text from the TextBox is transferred to the TextBlock. Since it can be useful to be able to style the TextBlock and to provide InputScope, I’ve also added a few DependencyProperties to enable that. The code is a little “smelly”, perhaps, because it could be refactored into a proper CustomControl, but what I have so far works well enough for me.

If you want to use it or just have a look, feel free to download the source code for TextBlockEditable.

Windows Phone 7 – Bing Map Phone/Desktop diffs: MapLayer.SetPosition() missing on Phone

October 2, 2010 10:54 pm

If you’re working on a Windows Phone 7 app that uses the Bing Map control, you might be interested in these little differences between the Desktop version and the Phone version of the map control.

1. The Location type on the Phone has no constructor that takes 2 parameters (the Desktop version does). You’ll have to construct a Location object with the default constructor and then set the Latitude and Longitude fields separately.

2. LocationRect also has no constructor that takes 2 parameters. Here you’ll need to do a little more work and assign the North, West, South and East fields appropriately after constructing a LocationRect object with the default constructor.

3. MapLayer has no static function called SetPosition that lets you map Location objects to something appropriate for a MapLayer. Use the regular instance member MapLayer.AddChild() instead.

With these changes, you can make the Desktop sample on the Bing developer site work on a Windows Phone 7 device.