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); return control.GetValue(DataContextProperty);
} }
static Design() internal static void ApplyDesignerProperties(Control target, Control source)
{ {
WidthProperty.Changed.Subscribe(OnChanged); if (source.IsSet(WidthProperty))
HeightProperty.Changed.Subscribe(OnChanged); target.Width = source.GetValue(WidthProperty);
DataContextProperty.Changed.Subscribe(OnChanged); if (source.IsSet(HeightProperty))
} target.Height = source.GetValue(HeightProperty);
if (source.IsSet(DataContextProperty))
static void OnChanged(PerspexPropertyChangedEventArgs args) target.DataContext = source.GetValue(DataContextProperty);
{
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;
} }
} }
} }

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

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

Loading…
Cancel
Save