diff --git a/src/Perspex.Application/Designer/Design.cs b/src/Perspex.Application/Designer/Design.cs new file mode 100644 index 0000000000..ef371c4f60 --- /dev/null +++ b/src/Perspex.Application/Designer/Design.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Perspex.Controls; + +namespace Perspex +{ + public static class Design + { + public static bool IsDesignMode { get; internal set; } + + public static readonly PerspexProperty HeightProperty = PerspexProperty + .RegisterAttached("Height", typeof (Design)); + + public static void SetHeight(TopLevel topLevel, double value) + { + topLevel.SetValue(HeightProperty, value); + } + + public static double GetHeight(TopLevel topLevel) + { + return (double) topLevel.GetValue(HeightProperty); + } + + public static readonly PerspexProperty WidthProperty = PerspexProperty + .RegisterAttached("Width", typeof (Design)); + + public static void SetWidth(TopLevel topLevel, double value) + { + topLevel.SetValue(WidthProperty, value); + } + + public static double GetWidth(TopLevel topLevel) + { + return (double) topLevel.GetValue(WidthProperty); + } + + static Design() + { + WidthProperty.Changed.Subscribe(OnChanged); + HeightProperty.Changed.Subscribe(OnChanged); + } + + static void OnChanged(PerspexPropertyChangedEventArgs args) + { + if(!IsDesignMode) + return; + if (args.Property == WidthProperty) + ((TopLevel) args.Sender).Width = (double) args.NewValue; + if (args.Property == HeightProperty) + ((TopLevel)args.Sender).Height = (double)args.NewValue; + } + } +} diff --git a/src/Perspex.Application/Designer/DesignerAssist.cs b/src/Perspex.Application/Designer/DesignerAssist.cs index 3228408087..52c1e57930 100644 --- a/src/Perspex.Application/Designer/DesignerAssist.cs +++ b/src/Perspex.Application/Designer/DesignerAssist.cs @@ -29,6 +29,7 @@ namespace Perspex.DesignerSupport public static void Init(Dictionary shared) { + Design.IsDesignMode = true; Api = new DesignerApi(shared) {UpdateXaml = UpdateXaml, SetScalingFactor = SetScalingFactor}; new DesignerApp(); } diff --git a/src/Perspex.Application/Perspex.Application.csproj b/src/Perspex.Application/Perspex.Application.csproj index 5b1cc42c4a..be9c29e1c7 100644 --- a/src/Perspex.Application/Perspex.Application.csproj +++ b/src/Perspex.Application/Perspex.Application.csproj @@ -89,6 +89,7 @@ Properties\SharedAssemblyInfo.cs +