public static void Init(Dictionary<string, object> shared) { Design.IsDesignMode = true; Api = new DesignerApi(shared) {UpdateXaml = UpdateXaml, SetScalingFactor = SetScalingFactor}; Application.RegisterPlatformCallback(Application.InitializeWin32Subsystem); var plat = (IPclPlatformWrapper) Activator.CreateInstance(Assembly.Load(new AssemblyName("Perspex.Win32")) .DefinedTypes.First(typeof (IPclPlatformWrapper).GetTypeInfo().IsAssignableFrom).AsType()); var app = plat.GetLoadedAssemblies() .SelectMany(a => a.DefinedTypes) .Where(typeof (Application).GetTypeInfo().IsAssignableFrom).FirstOrDefault(t => t.Assembly != typeof (Application).GetTypeInfo().Assembly); if (app == null) new DesignerApp(); else Activator.CreateInstance(app.AsType()); }
public static void Init(Dictionary <string, object> shared) { Design.IsDesignMode = true; Api = new DesignerApi(shared) { UpdateXaml = UpdateXaml, SetScalingFactor = SetScalingFactor }; Application.RegisterPlatformCallback(Application.InitializeWin32Subsystem); var plat = (IPclPlatformWrapper)Activator.CreateInstance(Assembly.Load(new AssemblyName("Perspex.Win32")) .DefinedTypes.First(typeof(IPclPlatformWrapper).GetTypeInfo().IsAssignableFrom).AsType()); TypeInfo app = null; foreach (var asm in plat.GetLoadedAssemblies()) { if (Equals(asm, typeof(Application).GetTypeInfo().Assembly)) { continue; } try { app = asm.DefinedTypes.Where(typeof(Application).GetTypeInfo().IsAssignableFrom).FirstOrDefault(); if (app != null) { break; } } catch { //Ignore, Assembly.DefinedTypes threw an exception, we can't do anything about that } } if (app == null) { new DesignerApp(); } else { Activator.CreateInstance(app.AsType()); } }
public static void Init(Dictionary <string, object> shared) { Design.IsDesignMode = true; Api = new DesignerApi(shared) { UpdateXaml = UpdateXaml, SetScalingFactor = SetScalingFactor }; Application.RegisterPlatformCallback(Application.InitializeWin32Subsystem); var plat = (IPclPlatformWrapper)Activator.CreateInstance(Assembly.Load(new AssemblyName("Perspex.Win32")) .DefinedTypes.First(typeof(IPclPlatformWrapper).GetTypeInfo().IsAssignableFrom).AsType()); var app = plat.GetLoadedAssemblies() .SelectMany(a => a.DefinedTypes) .Where(typeof(Application).GetTypeInfo().IsAssignableFrom).FirstOrDefault(t => t.Assembly != typeof(Application).GetTypeInfo().Assembly); if (app == null) { new DesignerApp(); } else { Activator.CreateInstance(app.AsType()); } }
private void DoInit(string targetExe, StringBuilder logger) { _appDir = Path.GetFullPath(Path.GetDirectoryName(targetExe)); Directory.SetCurrentDirectory(_appDir); Action<string> log = s => { UpdateState(s); logger.AppendLine(s); }; log("Loading assemblies from " + _appDir); var asms = new List<Assembly>(); foreach(var asm in Directory.GetFiles(_appDir).Where(f=>f.ToLower().EndsWith(".dll")||f.ToLower().EndsWith(".exe"))) try { log("Trying to load " + asm); asms.Add(Assembly.LoadFrom(asm)); } catch (Exception e) { logger.AppendLine(e.ToString()); } log("Looking up Perspex types"); BuildMetadataAndSendMessageAsync(asms); log("Initializing built-in designer"); var dic = new Dictionary<string, object>(); Api = new DesignerApi(dic) {OnResize = OnResize, OnWindowCreated = OnWindowCreated}; LookupStaticMethod("Perspex.DesignerSupport.DesignerAssist", "Init").Invoke(null, new object[] {dic}); _window = new Control { Controls = { new ElementHost() { Child = new InProcDesignerView(_appModel), Dock = DockStyle.Fill } } }; _window.CreateControl(); new Timer {Interval = 200, Enabled = true}.Tick += delegate { XamlUpdater(); }; _comm.SendMessage(new WindowCreatedMessage(_window.Handle)); _initSuccess = true; }