Browse Source

Added Design.Width, Design.Height and Design.DataContext attached properties

Fixes #152
Fixes #153
pull/335/head
Nikita Tsukanov 11 years ago
parent
commit
1c36606fa6
  1. 56
      src/Perspex.Application/Designer/Design.cs
  2. 1
      src/Perspex.Application/Designer/DesignerAssist.cs
  3. 1
      src/Perspex.Application/Perspex.Application.csproj

56
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<double> HeightProperty = PerspexProperty
.RegisterAttached<TopLevel, double>("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<double> WidthProperty = PerspexProperty
.RegisterAttached<TopLevel, double>("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;
}
}
}

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

@ -29,6 +29,7 @@ namespace Perspex.DesignerSupport
public static void Init(Dictionary<string, object> shared)
{
Design.IsDesignMode = true;
Api = new DesignerApi(shared) {UpdateXaml = UpdateXaml, SetScalingFactor = SetScalingFactor};
new DesignerApp();
}

1
src/Perspex.Application/Perspex.Application.csproj

@ -89,6 +89,7 @@
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Application.cs" />
<Compile Include="Designer\Design.cs" />
<Compile Include="Designer\DesignerAssist.cs" />
<Compile Include="Designer\DesignerApi.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

Loading…
Cancel
Save