15 changed files with 261 additions and 85 deletions
@ -0,0 +1,58 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using OmniXaml; |
|||
using Perspex.Controls; |
|||
using Perspex.Controls.Platform; |
|||
using Perspex.Markup.Xaml; |
|||
using Perspex.Themes.Default; |
|||
|
|||
namespace Perspex.Designer |
|||
{ |
|||
class Designer |
|||
{ |
|||
class DesignerApp : Application |
|||
{ |
|||
public DesignerApp() |
|||
{ |
|||
RegisterServices(); |
|||
//For now we only support windows
|
|||
InitializeSubsystems(2); |
|||
Styles = new DefaultTheme(); |
|||
} |
|||
} |
|||
|
|||
public static DesignerApi Api { get; set; } |
|||
|
|||
public static void Init(Dictionary<string, object> shared) |
|||
{ |
|||
Api = new DesignerApi(shared) {UpdateXaml = UpdateXaml}; |
|||
new DesignerApp(); |
|||
} |
|||
|
|||
static Window s_currentWindow; |
|||
|
|||
private static void UpdateXaml(string xaml) |
|||
{ |
|||
|
|||
Window window; |
|||
using (PlatformManager.DesignerMode()) |
|||
{ |
|||
var obj = ((XamlXmlLoader)new PerspexXamlLoader()).Load(new MemoryStream(Encoding.UTF8.GetBytes(xaml))); |
|||
window = obj as Window; |
|||
if (window == null) |
|||
{ |
|||
window = new Window() {Content = obj}; |
|||
} |
|||
} |
|||
s_currentWindow?.Close(); |
|||
s_currentWindow = window; |
|||
window.Show(); |
|||
Api.OnWindowCreated?.Invoke(window.PlatformImpl.Handle.Handle); |
|||
Api.OnResize?.Invoke(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Perspex.Designer |
|||
{ |
|||
class DesignerApi |
|||
{ |
|||
private readonly Dictionary<string, object> _inner; |
|||
|
|||
public DesignerApi(Dictionary<string, object> inner) |
|||
{ |
|||
_inner = inner; |
|||
} |
|||
|
|||
object Get([CallerMemberName] string name = null) |
|||
{ |
|||
object rv; |
|||
_inner.TryGetValue(name, out rv); |
|||
return rv; |
|||
} |
|||
|
|||
void Set(object value, [CallerMemberName] string name = null) |
|||
{ |
|||
_inner[name] = value; |
|||
} |
|||
|
|||
public Action<string> UpdateXaml |
|||
{ |
|||
get { return (Action<string>) Get(); } |
|||
set {Set(value); } |
|||
} |
|||
|
|||
public Action OnResize |
|||
{ |
|||
get { return (Action) Get(); } |
|||
set { Set(value);} |
|||
} |
|||
|
|||
public Action<IntPtr> OnWindowCreated |
|||
{ |
|||
set { Set(value); } |
|||
get { return (Action<IntPtr>) Get(); } |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Perspex.Platform |
|||
{ |
|||
public interface IWindowingPlatform |
|||
{ |
|||
IWindowImpl CreateWindow(); |
|||
IWindowImpl CreateDesignerFriendlyWindow(); |
|||
IPopupImpl CreatePopup(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue