Browse Source

Merge pull request #726 from AvaloniaUI/fixes/704-canvas-right-bottom

Fix canvas positioning.
pull/736/head
Steven Kirk 10 years ago
committed by GitHub
parent
commit
a4aed80c52
  1. 8
      src/Avalonia.Controls/Canvas.cs
  2. 1
      tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj
  3. 112
      tests/Avalonia.Controls.UnitTests/CanvasTests.cs

8
src/Avalonia.Controls/Canvas.cs

@ -22,25 +22,25 @@ namespace Avalonia.Controls
/// Defines the Left attached property.
/// </summary>
public static readonly AttachedProperty<double> LeftProperty =
AvaloniaProperty.RegisterAttached<Canvas, Control, double>("Left");
AvaloniaProperty.RegisterAttached<Canvas, Control, double>("Left", double.NaN);
/// <summary>
/// Defines the Top attached property.
/// </summary>
public static readonly AttachedProperty<double> TopProperty =
AvaloniaProperty.RegisterAttached<Canvas, Control, double>("Top");
AvaloniaProperty.RegisterAttached<Canvas, Control, double>("Top", double.NaN);
/// <summary>
/// Defines the Right attached property.
/// </summary>
public static readonly AttachedProperty<double> RightProperty =
AvaloniaProperty.RegisterAttached<Canvas, Control, double>("Right");
AvaloniaProperty.RegisterAttached<Canvas, Control, double>("Right", double.NaN);
/// <summary>
/// Defines the Bottom attached property.
/// </summary>
public static readonly AttachedProperty<double> BottomProperty =
AvaloniaProperty.RegisterAttached<Canvas, Control, double>("Bottom");
AvaloniaProperty.RegisterAttached<Canvas, Control, double>("Bottom", double.NaN);
/// <summary>
/// Initializes static members of the <see cref="Canvas"/> class.

1
tests/Avalonia.Controls.UnitTests/Avalonia.Controls.UnitTests.csproj

@ -95,6 +95,7 @@
</Choose>
<ItemGroup>
<Compile Include="AppBuilderTests.cs" />
<Compile Include="CanvasTests.cs" />
<Compile Include="ClassesTests.cs" />
<Compile Include="LayoutTransformControlTests.cs" />
<Compile Include="Presenters\ItemsPresenterTests_Virtualization_Simple.cs" />

112
tests/Avalonia.Controls.UnitTests/CanvasTests.cs

@ -0,0 +1,112 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Avalonia.Controls.Shapes;
using Xunit;
namespace Avalonia.Controls.UnitTests
{
public class CanvasTests
{
[Fact]
public void Left_Property_Should_Work()
{
Rectangle rect;
var target = new Canvas
{
Width = 400,
Height = 400,
Children =
{
(rect = new Rectangle
{
MinWidth = 20,
MinHeight = 25,
[Canvas.LeftProperty] = 30,
})
}
};
target.Measure(new Size(400, 400));
target.Arrange(new Rect(target.DesiredSize));
Assert.Equal(new Rect(30, 0, 20, 25), rect.Bounds);
}
[Fact]
public void Top_Property_Should_Work()
{
Rectangle rect;
var target = new Canvas
{
Width = 400,
Height = 400,
Children =
{
(rect = new Rectangle
{
MinWidth = 20,
MinHeight = 25,
[Canvas.TopProperty] = 30,
})
}
};
target.Measure(new Size(400, 400));
target.Arrange(new Rect(target.DesiredSize));
Assert.Equal(new Rect(0, 30, 20, 25), rect.Bounds);
}
[Fact]
public void Right_Property_Should_Work()
{
Rectangle rect;
var target = new Canvas
{
Width = 400,
Height = 400,
Children =
{
(rect = new Rectangle
{
MinWidth = 20,
MinHeight = 25,
[Canvas.RightProperty] = 30,
})
}
};
target.Measure(new Size(400, 400));
target.Arrange(new Rect(target.DesiredSize));
Assert.Equal(new Rect(350, 0, 20, 25), rect.Bounds);
}
[Fact]
public void Bottom_Property_Should_Work()
{
Rectangle rect;
var target = new Canvas
{
Width = 400,
Height = 400,
Children =
{
(rect = new Rectangle
{
MinWidth = 20,
MinHeight = 25,
[Canvas.BottomProperty] = 30,
})
}
};
target.Measure(new Size(400, 400));
target.Arrange(new Rect(target.DesiredSize));
Assert.Equal(new Rect(0, 345, 20, 25), rect.Bounds);
}
}
}
Loading…
Cancel
Save