Category: Windows Phone

  • Page Header Styles

    The page header is the small text you see across the top of most apps, often in all uppercase. When you create a new Windows Phone app from the default templates you’ll get something like this created in your MainPage.xaml

    <TextBlock Text=”MY APPLICATION” Style=”{StaticResource PhoneTextNormalStyle}” Margin=”12,0″/>

    The annoying thing about this is this is not the same format as built-in apps. The font size is wrong and so is the weight. Rather than manually fixing up every instance I define the following style in the App.xaml:

    <Style x:Name=”PhoneTextPageHeaderStyle” BasedOn=”{StaticResource PhoneTextNormalStyle}” TargetType=”TextBlock”>
       <Setter Property=”FontSize” Value=”{StaticResource PhoneFontSizeMedium}”/>
       <Setter Property=”FontFamily” Value=”{StaticResource PhoneFontFamilySemiBold}”/>
    </Style>

    Then my page XAML becomes:-

    <TextBlock Text=”MY APPLICATION” Style=”{StaticResource PhoneTextPageHeaderStyle}”/>

    My app is now consistent with built-in apps!

    [Updated with simplified Style XAML removing hard-coded font size]

  • Sending an Email with an Attachment on Windows Phone (Sort of)

    From it’s initial release Windows Phone has had a method to programmatically send an email from code. In keeping with the mantra that the user is in control it has always been a method to populate the email but allow the user to decide to modify, send or cancel. Despite much demand the ability to attach files has not been made available. As a user you can attach a picture to an outgoing email but the phone can receive a wider variety of types. There is, albeit not as obvious, a method to send a picture attachment via email but there are caveats.

    The ShareMediaTask only allows you to specify the image to use and not the transport to send via or an accompanying message. In fact it basically is just running the “share…” menu found in the built in Pictures app. The other caveat is that the picture must be in a location that the system can read from so a path to your isolated storage won’t work. You can however copy an image to the user’s pictures library. Another annoyance is that once you’ve copied a picture to the library you can’t delete it – only the user has the ability to do this.

    Microsoft.Xna.Framework.Media.MediaLibrary ml = new Microsoft.Xna.Framework.Media.MediaLibrary();
    Microsoft.Xna.Framework.Media.Picture pic = ml.SavePicture(“mypic.png”, stream);
    path = Microsoft.Xna.Framework.Media.PhoneExtensions.MediaLibraryExtensions.GetPath(pic);

    The above code takes an image stream and placed it in the library and gets a true file path. The code to initiate the share operation is equally simple:-

    Microsoft.Phone.Tasks.ShareMediaTask shareMediaTask = new Microsoft.Phone.Tasks.ShareMediaTask();
    shareMediaTask.FilePath = path;
    shareMediaTask.Show();

    That’s all there is to it – you don’t get any feedback on what option was chosen (or whether the operation was cancelled).

    I’ll be discussing some more around sharing various types of data at my talk on this coming Tuesday for WPUG Manchester which is titled “Bluetooth and NFC for Windows Phone and Beyond” where I’ll be unveiling some ways to make “Charming” apps for Windows Phone.

  • Deployment Parts in a Windows Phone App

    My apologies in advance as this is a little bit of an obscure scenario but I thought I’d share this information in case others found it useful.

    Imagine if you will the following scenario. You have a dll project which can make use of other “provider” libraries. These are optional and the main dll should function regardless of whether the provider is present or not. The issue is this – you need to detect from your library whether this provider dll is present at runtime. In traditional .NET you would use reflection but not all aspects of this are available in the Silverlight model. Instead there is a way to interrogate all the assemblies within the XAP from the Deployment class. The following code snippet shows how to check for a particular assembly:-

    bool featurePresent = false;

    foreach (System.Windows.AssemblyPart part in System.Windows.Deployment.Current.Parts)
    {
       if (part.Source.ToString().Contains(“FeatureAssemblyName”))
       {
          featurePresent = true;
          break;
       }
    }

  • Launching PDF Documents

    In Windows Phone 8 the Windows.System.Launcher class allows you to open files with apps which are registered to handle them. On Windows Phone you have built in support for Office documents and audio and video formats. Lets say you want to open a PDF either remotely or downloaded by your app. There isn’t a built-in PDF viewer but there are several available including free readers by both Microsoft and Adobe. If your user doesn’t already have one installed there are some extra steps. The first thing that happens is that the user is prompted like so:-

    If the user taps yes the phone will display a store search for apps which are associated with the file type:-

     

    Not sure why Adobe Reader isn’t in this list and why it looks like the last entry is a game 🙂 but at least the top couple of entries seem like they will do the job.

  • Prototyping with Infragistics Indigo

    I recently needed to create a prototype for a Windows Phone application and having recently discovered it I decided to use Indigo Studio to build it. The application is not particularly designed for Windows Phone however it has enough standard UI controls and customisations to make it easy to create phone mockups. They say a picture says a thousand words so why not have a look at a sample I created showing a few screens of an imaginary phone application.

    http://indigo.infragistics.com/prototype/XX47K8P4

    In posting that link I’ve just highlighted one of the great features – you can build a prototype and then share it (either on Infragistics servers or your own) via the web. The Silverlight magic then gives your clients a rich experience to understand the scope and user flow around the application. I intend to revisit this in a series of blog posts to discuss gotchas and tips for creating Windows Phone prototypes. Oh and one of the best features – it’s free!

  • Working with .png Images

    In my previous post I discovered a limitation with using the Share… extension point in the Photos app. The good news is that from within your own app you can open .png files. For this you can use the PhotoChooserTask which has been available since Windows Phone 7. This presents the user with essentially the same UI as the Photos app and you can browse the Screeshots folder and select those .png files. The Completed event returns you a PhotoResult containing the raw stream and the filename which you can use to open the file. Because .png access is available this way it seems an odd decision that it is not supported from the Photos app itself. The moral of the story – provide multiple methods for your user to select files…

  • Photos Extra Share and .png

    On Windows Phone 8 it is possible to register your app with the Share… extension point on the photo viewer. This allows your app to receive an image file and process it whether that is sending it to an online service or manipulating it on the device. I found recently an odd quirk with the feature. I setup the extension following the MSDN documentation. I wanted to test on my captured screenshots on the device so I went into the screenshots folder, selected an image and tapped share. While a range of system extensions were shown my custom app was not. I later discovered that it works in other albums. The reason as it turns out is that all screenshots are captured as .png files and camera images are .jpg and for whatever reason photo extras are not enabled for .png files. I searched online and there was a forum discussion but it is still awaiting a formal confirmation from Microsoft that this is expected behaviour.

    http://social.msdn.microsoft.com/Forums/en-US/wpdevelop/thread/095a3300-111e-46d8-968a-3af1036504b7

  • 32feet.NET for Windows Phone

    With the recent announcement of Windows Embedded Handheld 8 it seems fitting to discuss something related to industrial and line-of-business applications which you can develop now on the Windows Phone platform.

    I’ve released the first drop of 32feet.NET for Windows Phone 8 to our CodePlex site and NuGet. Because the programming model on Windows Phone (based on Windows Runtime StreamSockets) this is a separate package and doesn’t follow the programming model of the main 32feet.NET release. Windows Phone 8 supports Bluetooth programming out-of-the-box it is not straight-forward as it is build around the Windows Runtime Peer networking APIs but is different to the Windows 8 implementation. The aim of the 32feet library for Windows Phone is to simplify common tasks. This initial release adds the following features:-

    • Strongly typed extension methods for ConnectAsync which accept service Guids or numerical port numbers
    • BluetoothDevicePicker which offers an easy way for a user to select a device. Equivalent to the SelectBluetoothDeviceDialog in the core 32feet library.
    • Common Bluetooth service Guids
    • Bluetooth Barcode scanner sample. This sample app connects to a Motorola CS3070 scanner and allows input of Barcodes to the device screen. It should also work with other Bluetooth serial based scanners.

    This is just a first release and we will be continuing to develop the library as well as add further localisation and samples. For example to demonstrate connecting to applications running on the desktop (Sorry not Windows Store apps currently). Your feedback is valuable so please visit the CodePlex project site to provide feedback.

    There is a NuGet package available for the Windows Phone flavour of 32feet.NET to allow you to easily add it to your projects:-

    http://nuget.org/packages/32feet.NET.Phone

  • Persist Bluetooth Addresses on Windows Phone 8

    The Bluetooth API on Windows Phone 8 is based around some customisations to the Proximity APIs which are part of the Windows API introduced with Windows 8. When you “discover” devices you can retrieve a collection of device identifiers for paired devices. The first time you perform a task you will want to use this mechanism to select the appropriate device. However you may want your app to remember a specific device and try to connect again on subsequent attempts. In the old .NET world with 32feet.NET we have a constructor for BluetoothAddress which allows you to supply the address in a variety of string or numeric forms. In the Windows API the Windows.Networking.HostName type is used to represent a host name whether it is for a Bluetooth device or an IP address. Normally the read-only Type property will indicate the type of the host.

    In order to store a Bluetooth address for later use you should save the RawName property which for Bluetooth devices is in the form “(11:22:33:44:55:66)”. The dotted hex notation is fairly common but notice the address is wrapped in brackets. Now to restore this address in a HostName instance you can later use to open a socket you can use:-

    HostName storedHostName = new HostName(storedRawName);

    You’ll notice that this sets the host name and correctly sets the Type property to Bluetooth.

  • iCalendar Files on Windows Phone 8

    iCalendar files are based on the set of data exchange specifications which also includes vCards. You may come across them either in emails or from a website. For example some sites which sell travel tickets allow you to download your itinerary in an iCalendar file. While Windows Phone has always supported vCards for contact information it doesn’t recognise iCal files.

    Since Windows Phone 8 introduced the ability to register for file associations this allowed me to use some old code I wrote back in the days of Pocket Outlook on Windows CE and Windows Mobile. My free iCalendar Import application has just become available in the Store for Windows Phone 8. You can download it from the link below. I’d welcome any feedback. There are some limitations on the supported event types – there is no way to insert recurring appointments into the user’s calendar so this supports single events only.

    http://www.windowsphone.com/s?appid=95287e45-05d7-4a63-aa82-619192cb1713