Browse Source
Merge pull request #9274 from AvaloniaUI/fixes/viewbox-datacontext-binding
Set Viewbox container logical parent.
pull/9278/head
Max Katz
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
22 additions and
0 deletions
-
src/Avalonia.Controls/Viewbox.cs
-
tests/Avalonia.Controls.UnitTests/ViewboxTests.cs
|
|
|
@ -42,6 +42,7 @@ namespace Avalonia.Controls |
|
|
|
// can be applied independently of the Viewbox and Child transforms.
|
|
|
|
_containerVisual = new ViewboxContainer(); |
|
|
|
_containerVisual.RenderTransformOrigin = RelativePoint.TopLeft; |
|
|
|
((ISetLogicalParent)_containerVisual).SetParent(this); |
|
|
|
VisualChildren.Add(_containerVisual); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using Avalonia.Controls.Shapes; |
|
|
|
using Avalonia.Data; |
|
|
|
using Avalonia.LogicalTree; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.UnitTests; |
|
|
|
@ -207,6 +208,26 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
Assert.Equal(new Size(200, 200), target.DesiredSize); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Child_DataContext_Binding_Works() |
|
|
|
{ |
|
|
|
var data = new |
|
|
|
{ |
|
|
|
Foo = "foo", |
|
|
|
}; |
|
|
|
|
|
|
|
var target = new Viewbox() |
|
|
|
{ |
|
|
|
DataContext = data, |
|
|
|
Child = new Canvas |
|
|
|
{ |
|
|
|
[!Canvas.DataContextProperty] = new Binding("Foo"), |
|
|
|
}, |
|
|
|
}; |
|
|
|
|
|
|
|
Assert.Equal("foo", target.Child.DataContext); |
|
|
|
} |
|
|
|
|
|
|
|
private bool TryGetScale(Viewbox viewbox, out Vector scale) |
|
|
|
{ |
|
|
|
if (viewbox.InternalTransform is null) |
|
|
|
|