mirror of https://github.com/AMT-Cheif/Stylet.git
Don't complain that the IoC container isn't initialized if we're in design mode
This commit is contained in:
parent
bbbec9524a
commit
fbebf8104c
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,9 @@ namespace Stylet
|
|||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue