Don't complain that the IoC container isn't initialized if we're in design mode

This commit is contained in:
Antony Male 2014-03-19 12:45:59 +00:00
parent bbbec9524a
commit fbebf8104c
2 changed files with 24 additions and 1 deletions

View File

@ -1,15 +1,19 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
namespace Stylet namespace Stylet
{ {
public static class Execute public static class Execute
{ {
public static SynchronizationContext SynchronizationContext; public static SynchronizationContext SynchronizationContext;
private static bool? inDesignMode;
public static void OnUIThread(Action action) public static void OnUIThread(Action action)
{ {
@ -46,5 +50,22 @@ namespace Stylet
return Task.FromResult(false); 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);
}
}
} }
} }

View File

@ -16,7 +16,9 @@ namespace Stylet
static View() static View()
{ {
viewManager = IoC.Get<IViewManager>(); // Don't complain that IoC is not initialized if we're in design mode
if (!Execute.InDesignMode)
viewManager = IoC.Get<IViewManager>();
} }
public static object GetActionTarget(DependencyObject obj) public static object GetActionTarget(DependencyObject obj)