Thursday, June 19, 2014

Using WiDi on the Dell XPS 12 running Windows 8.1

There seems to be a bit of confusion on how to get WiDi up and running on some newer devices, especially if they don’t ship with the WiDi software pre-installed.  This was the case with my Dell XPS 12.

So really, all you need to do is go here but I’ll walk through some of the steps since things have changed since Windows 7 and the documentation hasn’t all been updated: 

Go to the link above and run the WiDi update tool – it’s going to make sure you have all of the nessesary drivers up to date.  After a fresh Windows 8.1 installation the WiDi updater upgraded my WiFi drivers to version 17.x.

On Windows 8.1 you no longer need a stand-alone WiDi app, it’s integrated into Windows.

Step 1: Turn on your TV & WiDi receiver, and make sure you can see the WiDi connection screen on your TV.  I’m using the NetGear PTV3000.

Step 2: Open the charms bar (swipe in from the right) and click on “Settings” and then “Change PC Settings” at the bottom of the charm flyout.

Step 3: Select “Display” on the left and then scroll to the bottom and click on “Connect to a wireless display”.

Step 4: Click “Add a wireless display” on the flyout.


Step 5: Allow Windows to search and then select your WiDi device from the list







My display lags slighlt when connected, but it works very well and the connection is stable.

If you’re having connection problems, make sure your WiDi receiver’s firmware is up to date.  I did need to update my Netgear PVT3000.

Friday, June 13, 2014

Detecting 2 in 1 state in WPF C# (Slate or Clamshell mode)

I’ve been wanting to experiment with changing UIs in my code between “tablet” mode and the “laptop” mode on my new Dell XPS 12 (or any other Ultrabook 2 in 1 that happened across my desk).  There’s already a really great article on how us developers can detect the state change on Intel’s developer portal; but the example code is in C++ and not my preferred C#.
Before we go any further, I recommend heading over to and reading Detecting Slate/Clamshell Mode & Screen Orientation in a 2 in 1.
The code we’re looking to implement is basically this (done in a WndProc):

   2:     if (wcscmp ( TEXT ("ConvertibleSlateMode"), (TCHAR*)lParam ) == 0)

   3:         NotifySlateModeChange ();

   4:    else if wcscmp ( TEXT ("SystemDockMode"), (TCHAR*)lParam ) == 0)

   5:         NotifyDockingModeChange ();
Simply stated, we need to monitor WM_SETTINGCHANGE or equivalent, detect which state we’re in, and respond accordingly.
Now that we know what our goal is, let’s make it work in a modern WPF C# application.  I looked a few approaches before settling on my solution, and hopefully it will make sense why I’ve done it this way as we work through the code.
Our first step is to import user32.dll so we can define and use the GetSystemMetrics method.

   1: public partial class MainWindow : Window

   2: {

   3:     [DllImport("user32.dll")]

   4:     static extern int GetSystemMetrics(SystemMetric smIndex);

   5:     ...

To do that we’ll need to reference the InteropServices:
using System.Runtime.InteropServices;
At this point you may have noticed that we don’t have the SystemMetric enum defined.  We could create our own with just the two metrics we need, but we might as well jump over to and get a fairly complete enum, and just copy that into our window class or somewhere else convenient (this might just be useful for other purposes as well): 
Unfortunately this list doesn’t contain the two metrics we want to check against as we saw in the Intel doc, namely
so we’ll add these to the end of the enum ourselves:

   1: public enum SystemMetric

   2: {   

   3:    ...    

   4:    SM_CONVERTABLESLATEMODE = 0x2003,    

   5:    SM_SYSTEMDOCKED = 0x2004

   6: }

(* after writing this post I decided I should update the page so the enum should now be up to date)
We’re almost ready to watch for the 2 in 1 state change.  In C++ we would just capture the WM_SETTINGSCHANGED message.
We could do this in C# by overriding OnSourceInitialized() and hooking into the WndProc.  Truth be told this was my first approach.  But on my machine I wasn’t receiving “SystemDockMode” from the lParam – it would always give me “ConvertableSlateMode” regardless of the state.  
So I decided to do it the “C# way” and just watch UserPreferenceChanging.  To try it out just add 

   1: SystemEvents.UserPreferenceChanging += SystemEvents_UserPreferenceChanging; 
to the constructor and create a method with the correct signature.  You’ll need to include “using Microsoft.Win32;” for SystemEvents.
We’ll get a UserPreferenceChanging event every time the device changes state, and it will come in under the General Category of UserPreferenceCategory. This is passed in with the UserPreferenceChagingEventArgs.  Unfortunately we don’t get any additional information, and we don’t have access to the lParam as we would if we were handling the message directly.
And that’s where the GetSystemMetrics() method comes in.  We’ll simply query for the state every time we change comes in under the General category.  Uou’ll likely want to add some logic to remember your current state and only update your UI if it changes.
See the code below: 

   1: void SystemEvents_UserPreferenceChanging(object sender, UserPreferenceChangingEventArgs e)

   2: {    

   3:     if(e.Category == UserPreferenceCategory.General)    

   4:     {        

   5:         if (GetSystemMetrics(SystemMetric.SM_CONVERTABLESLATEMODE) == 0)        

   6:         {            

   7:             Debug.WriteLine("detected slate mode");        

   8:         }        

   9:         else if (GetSystemMetrics(SystemMetric.SM_SYSTEMDOCKED) == 0)        

  10:         {            

  11:             Debug.WriteLine("detected docked mode");        

  12:         }    

  13:     }

  14: }
And that should give you everything you need to get started making 2 in 1 C# apps in WPF. 

Finally, there’s a sample project with all of the above code on github here:


Happy Coding!

Monday, June 2, 2014

Window Phone 8 Assets / Icon / Tile sizes


If you’ve tried to find the recommended tile sizes for Windows Phone 8.x you probably ended up here: 


And you definitely should read this article carefully.  However if you’re just looking to make some simple static assets for your Windows Phone 8 app its not obvious what’s required and or what’s best practice.

SO here’s this list:

  Scale 100 Scale 140 Scale 240
Square Logo 71x71 99x99 170x170
Logo 150x150 210x210 360x360
Logo Wide 310x150 434x210 744x360
Small Logo 44x44 62x62 106x106
Store Logo 50x50 70x70 120x120
Badge Logo 24x24 33x33 58x58

You’ll notice a couple of them overlap with Windows Store (but not many).


And for the Splash / Launch Images you’ll want to make:

480x800, 672x1120 & 1152x1920


If I come across a good site or tool for auto creating the icons I’ll make sure to add it here. 

For more information: