Blog

  • Determine Light or Dark Theme with WP7 RTM

    In the previous Beta release you had to compare the RGB values of the background brush to determine if the theme was Light (White background) or Dark (Black background). Now there is an additional resource you can query:-

    Visibility v = (Visibility)Resources["PhoneLightThemeVisibility"];
     
    if (v == System.Windows.Visibility.Visible)
    {
        ImageBrush ib = new ImageBrush();
        Uri u = new Uri("PanoramaBack2.png", UriKind.Relative);
        ib.ImageSource = new System.Windows.Media.Imaging.BitmapImage(u);
        PanoramaControl.Background = ib;
    }

    .csharpcode, .csharpcode pre
    {
    font-size: small;
    color: black;
    font-family: consolas, “Courier New”, courier, monospace;
    background-color: #ffffff;
    /*white-space: pre;*/
    }
    .csharpcode pre { margin: 0em; }
    .csharpcode .rem { color: #008000; }
    .csharpcode .kwrd { color: #0000ff; }
    .csharpcode .str { color: #006080; }
    .csharpcode .op { color: #0000c0; }
    .csharpcode .preproc { color: #cc6633; }
    .csharpcode .asp { background-color: #ffff00; }
    .csharpcode .html { color: #800000; }
    .csharpcode .attr { color: #ff0000; }
    .csharpcode .alt
    {
    background-color: #f4f4f4;
    width: 100%;
    margin: 0em;
    }
    .csharpcode .lnum { color: #606060; }

    Any time you use a background image you can check the PhoneLightThemeVisibility resource and switch between different versions of the image to provide the best experience with either Black or White text.

  • Using Microsoft.Phone.Tasks in the Emulator

    The Windows Phone 7 emulator is very limited compared with the real phones so there are no built in applications other than Internet Explorer. This can make it difficult to test some of the APIs which interact with data on the device. Luckily there is a way to load contact data onto the emulator which allows you to use these tasks as if you were working against real contacts from your Exchange server or wherever. The trick to this is that the system supports the vCard standard which allows you to attach contact items to emails or via the web. Internet Explorer understands vCard files and provides the option to save them in the People list on the phone. For example you can browse to https://inthehand.com/share.vcf to see how this process works. From within your application you can also use the WebBrowserTask (AFAIK it does not work when you host the WebBrowser control in your own app).

    Tap the contact image to open in a new contact page:-

    You can make changes to the contact and then tap the disk icon to save.

    When you close the emulator the contents are not persisted so you’ll have to repeat this each time you launch the emulator. Unfortunately this doesn’t appear to support vCard files containing multiple entries. However having just one entry in there allows you to test your app flow where you have a contact picking scenario.

    If you want to test the PhotoChooserTask you can also import images to the emulator. Simply visit any website and tap and hold over an image – select “save picture” from the context menu which pops up. These are placed in a “Saved Pictures” folder.

    The PhoneCallTask and SmsComposeTask work as expected (like the Windows Mobile emulators there is a fake mobile network). The EmailComposeTask does not work as there is no account on the emulator and no way to add one. When you launch it you’ll get an error popup.

  • Windows Phone 7 Development Workshops

    Microsoft are running a series of development workshops across New Zealand (Auckland, Wellington, Dunedin, Christchurch and Hamilton) over September and October. Full details are on Nigel’s blog along with sign-up links. Places are limited so register today!

    http://blogs.msdn.com/b/nigel/archive/2010/09/09/windows-phone-7-introductory-development-workshop.aspx

  • DataContractSerializer and Internal types

    Under Silverlight only public types may be serialized with the DataContractSerializer. If you want to make your data classes internal to your assembly and serialise them for use in a WCF service you will find that the service call will fail at runtime with a SecurityException inside a misleading exception about inability to communicate with the service. There is a workaround however which involves exposing your internal types to the Silverlight base class libraries with the InternalsVisibleTo attribute. Simply add the following code to your AssemblyInfo.cs file:-

    1. [assembly: InternalsVisibleTo("System.Runtime.Serialization, PublicKey=00240000048000009400000006020000002400005253413100040000010001008d56c76f9e8649383049f383c44be0ec204181822a6c31cf5eb7ef486944d032188ea1d3920763712ccb12d75fb77e9811149e6148e5d32fbaab37611c1878ddc19e20ef135d0cb2cff2bfec3d115810c3d9069638fe4be215dbf795861920e5ab6f7db2e2ceef136ac23d5dd2bf031700aec232f6c6b1c785b4305c123b37ab")]

    If you use the DataContractJsonSerializer you must also add the System.Servicemodel.Web assembly (the public key is the same).

  • Review: .NET Compact Framework 3.5 Data Driven Applications

    Like Peter Nowak I was asked to review this recent release. Unfortunately due to other commitments it has taken the best part of a month to finish it. To avoid repeating the same points I recommend you read Peter’s review. While the current focus at Microsoft is on the upcoming Windows Phone 7 platform, we should not forget that there is still a demand for line of business applications for custom Windows CE platforms and Windows Mobile (and its Windows Embedded Handheld offspring) for enterprise devices.

    I think the format of following a real-world application through the book provides a nice thread to tie together the various concepts described but often with this kind of approach you find features are shoe-horned in to show off a particular technology – a good example in this case is the IrDA/Bluetooth transfer of accounts between agents in a Sales application. Peter noted that the book does not describe the current situation with Visual Studio 2010 and why 2008 is needed for .NETCF 3.5 development but I think this is excusable based on the timescales involved in writing a book and how clearly this message was communicated by Microsoft.

    The application design focuses exclusively on Windows Mobile and doesn’t cover issues when targeting other Windows CE platforms (such as Windows Mobiles enforced single-instance versus Windows CE default support for multiple instances of an application or just difference between the shells and screen layout). It also doesn’t cover form rotation and design for different DPI screens or implemented a locked-down kiosk mode. A personal gripe is the use of a SerialPort to do a Bluetooth transfer which is not the nicest solution, but then I suppose I’m biased.

    Ultimately there is some good content in the book but it is unfortunately let down by being late to the party and the application scenarios try too hard to be all things to all people and ultimately not always 100% believable. It provides a starting point to work from and introduces a lot of functional areas from data synchronisation through to automatic update.

  • Microsoft Surface Bluetooth Connect Code Sample

    APPA Mundi recently worked with the Microsoft Surface team to put together a code sample showing the exchange of information from a Surface to a nearby Bluetooth enabled phone using standard protocols. This means that any phone which supports standard Object Exchange (OBEX) protocols can receive items from the Surface without installing any client software.

    The sample code is available in the MSDN Code Gallery:-

    http://code.msdn.microsoft.com/surfacebluetooth

    This code sample is designed for use with the Microsoft Surface 1.0 SP1 SDK and makes use of the .NET Bluetooth library binary file available from https://32feet.net. The sample code is provided “as-is” and is not supported. Alongside the standard functionality in 32feet.NET the sample illustrates using the notifications supported in the desktop Windows API and shows how to consume these from within a WPF application (the API uses native Windows messages).

  • New Book on .NETCF 3.5 Development

    Despite Windows Phone 7 Development being all-the-rage at the moment I was recently informed of a new book on .NET Compact Framework development. I’ll be reviewing it shortly, in the mean time you can check out the details (including a free chapter download):-

    .NET Compact Framework Data Driven Applications

  • DDD-Day Sydney 17th July

    Following the format of the excellent Developer-Developer-Developer-Day events in the UK, Lewis Benge is organising an event on 17th July in Sydney. If you are in the Sydney area then I urge you to check out the website and register for this free event:-

    http://www.dddsydney.com

    As well as a range of .NET topics there will be a Windows Phone 7 session and labs.

  • 070-580: Windows Mobile 6.5 Application Development

    This may be a little late to the party but I thought I would share some information on this exam. Because you sign an NDA when you take the exam I cannot comment on specifics of the exam content, however I can offer some guidance on the study guide:-

    http://www.microsoft.com/learning/en/us/exam.aspx?ID=70-580

    This exam replaced the previous 070-540 exam which covered application development using Windows Mobile 5.0, .NET Compact Framework 2.0 and Visual Studio 2005. Therefore a large percentage of the material is the same between the two. The new topics come in the form of Widgets, LINQ, ADO.NET Sync Services and Windows Mobile Tools such as FakeGPS. The full list of skills measured can be read on the exam link above. There are a couple of oddities:–

    • The material is updated for .NETCF 3.5 by including LINQ but WCF is not listed.
    • ADO.NET Sync Services has never really been a core part of the development tools.
    • Finally one of the skills measured is creating a desktop installer for your application. There is not standard way of doing this but the guidance does exist (see list below) to put together a dll which acts as a custom install action within your desktop installer.

    So once you’ve familiarised yourself with all the skills measured you’ll skip to the next tab on Preparation Materials and find there is nothing at all listed. Here is a list I think will help with your preparation:-

    Microsoft Mobile Development Handbook – Microsoft Press. While the main book covers .NETCF 2.0 and Visual Studio 2005, the last chapter gives a run down on new features in Visual Studio 2008 and .NETCF 3.5 including LINQ. It ticks almost all of the Skills measured, there are a few articles which cover the new topics:-

    Developing Widgets for Windows Mobile 6.5 – MSDN. The Windows Mobile 6.5.3 SDK added some support for Widget development to Visual Studio 2008 but I find it just hangs Visual Studio. This article shows the “old” approach from creating the HTML, JavaScript and building the ZIP file and renaming.

    Programming Microsoft Synchronization Services for ADO.NET (Devices) – MSDN. Andy’s article describes Synchronization services from setting up and running synchronization through to optimisations for mobile use.

    Using the FakeGPS Utility – MSDN.

     

    The 70-580 exam is quite new and it is quite clear that if and when there is an exam created for Windows Phone 7 development it will by necessity be completely different. However for now 70-580 is the most up-to-date Microsoft exam for Mobility and is one of the requirements for the Mobility competency within the Microsoft Partner Program. Currently it doesn’t appear that there are any exams at all for Silverlight, but there are some coming in the next few months for .NET 4.0 and WPF.

  • Microsoft English 1.0

    More proof (if really needed) that Microsoft is abandoning English and making up its own language:-

    "We have noted your concern and we have given your feedback to our upstream."

    From Microsoft Subscriptions Support (TechNet/MSDN)