Friday, October 30, 2009

Writing designer friendly controls for Windows Mobile

One thing that you sometimes need when writing Visual Studio designer friendly controls for Windows Mobile, is knowing if your code is running in design time - which is essentially running on the desktop or not. You need to know this because if you are running on the desktop (design time) you don't want to call device specific dlls.

The following code can be used to determine this:
public static class DesignMode
{
private static byte _mode = 255;

public static bool IsTrue
{
get
{
if (_mode == 255)
_mode = AppDomain.CurrentDomain.FriendlyName.Contains("DefaultDomain")
? (byte)1 : (byte) 0;
return _mode == 1;
}
}
}
So essentially you can then code in your application:
if (DesignMode.IsTrue)
{
//don't call coredll.dll
}
else
{
//call coredll.dll
}