diff --git a/Stylet/Execute.cs b/Stylet/Execute.cs index 75fb0f4..f5cfd1e 100644 --- a/Stylet/Execute.cs +++ b/Stylet/Execute.cs @@ -1,15 +1,19 @@ using System; using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Windows; namespace Stylet { public static class Execute { public static SynchronizationContext SynchronizationContext; + private static bool? inDesignMode; public static void OnUIThread(Action action) { @@ -46,5 +50,22 @@ namespace Stylet return Task.FromResult(false); } } + + public static bool InDesignMode + { + get + { + if (inDesignMode == null) + { + var prop = DesignerProperties.IsInDesignModeProperty; + inDesignMode = (bool)DependencyPropertyDescriptor.FromProperty(prop, typeof(FrameworkElement)).Metadata.DefaultValue; + + if (inDesignMode.GetValueOrDefault(false) && Process.GetCurrentProcess().ProcessName.StartsWith("devenv", StringComparison.Ordinal)) + inDesignMode = true; + } + + return inDesignMode.GetValueOrDefault(false); + } + } } } diff --git a/Stylet/View.cs b/Stylet/View.cs index d96cdfb..1a3f163 100644 --- a/Stylet/View.cs +++ b/Stylet/View.cs @@ -16,7 +16,9 @@ namespace Stylet static View() { - viewManager = IoC.Get(); + // Don't complain that IoC is not initialized if we're in design mode + if (!Execute.InDesignMode) + viewManager = IoC.Get(); } public static object GetActionTarget(DependencyObject obj)