Browse Source

Apply design properties to tollevel

pull/335/head
Nikita Tsukanov 11 years ago
parent
commit
2c39da7153
  1. 27
      src/Perspex.Application/Designer/Design.cs
  2. 8
      src/Perspex.Application/Designer/DesignerAssist.cs

27
src/Perspex.Application/Designer/Design.cs

@ -49,24 +49,15 @@ namespace Perspex
{
return control.GetValue(DataContextProperty);
}
static Design()
{
WidthProperty.Changed.Subscribe(OnChanged);
HeightProperty.Changed.Subscribe(OnChanged);
DataContextProperty.Changed.Subscribe(OnChanged);
}
static void OnChanged(PerspexPropertyChangedEventArgs args)
{
if(!IsDesignMode)
return;
if (args.Property == WidthProperty)
((Control) args.Sender).Width = (double) args.NewValue;
if (args.Property == HeightProperty)
((Control)args.Sender).Height = (double)args.NewValue;
if (args.Property == DataContextProperty)
((Control) args.Sender).DataContext = args.NewValue;
internal static void ApplyDesignerProperties(Control target, Control source)
{
if (source.IsSet(WidthProperty))
target.Width = source.GetValue(WidthProperty);
if (source.IsSet(HeightProperty))
target.Height = source.GetValue(HeightProperty);
if (source.IsSet(DataContextProperty))
target.DataContext = source.GetValue(DataContextProperty);
}
}
}

8
src/Perspex.Application/Designer/DesignerAssist.cs

@ -60,18 +60,20 @@ namespace Perspex.DesignerSupport
{
Window window;
Control original;
using (PlatformManager.DesignerMode())
{
var obj = ((XamlXmlLoader)new PerspexXamlLoader()).Load(new MemoryStream(Encoding.UTF8.GetBytes(xaml)));
window = obj as Window;
original =(Control)((XamlXmlLoader)new PerspexXamlLoader()).Load(new MemoryStream(Encoding.UTF8.GetBytes(xaml)));
window = original as Window;
if (window == null)
{
window = new Window() {Content = obj};
window = new Window() {Content = original};
}
}
s_currentWindow?.Close();
s_currentWindow = window;
window.Show();
Design.ApplyDesignerProperties(window, original);
Api.OnWindowCreated?.Invoke(window.PlatformImpl.Handle.Handle);
Api.OnResize?.Invoke();
}

Loading…
Cancel
Save