I'm in the process of trying to use Portable Class Libraries to reduce my assembly per platform for my own MVVM framework.
So I currently have this code (inspired by @lbugnion MVVMLight)
public static bool IsInDesignModeStatic
{
get
{
if (!_isInDesignMode.HasValue)
{
#if SILVERLIGHT
_isInDesignMode = DesignerProperties.IsInDesignTool;
#else
var prop = DesignerProperties.IsInDesignModeProperty;
_isInDesignMode
= (bool)DependencyPropertyDescriptor
.FromProperty(prop, typeof(FrameworkElement))
.Metadata.DefaultValue;
// Just to be sure
if (!_isInDesignMode.Value
&& Process.GetCurrentProcess().ProcessName.StartsWith("devenv", StringComparison.Ordinal))
{
_isInDesignMode = true;
}
#endif
}
return _isInDesignMode.Value;
}
}
}
But when I try to use this inside PCL it doesn't recognize DesignerProperties and FrameworkElement, etc. How should I overcome this?
Thanks!
You can do it like I do in the MVVM Light PCL fork:
http://mvvmlight.codeplex.com/.../GalaSoft.MvvmLight (NET35)/ViewModelBase.cs
http://mvvmlight.codeplex.com/.../GalaSoft.MvvmLight/Helpers/DesignerPlatformLibrary.cs
Uses Reflection to load up and invoke the appropriate calls.