Browse Source
Merge pull request #12173 from danielmayost/tcc-fixes
[TransitioningContentControl] Manage his LogicalChildren
pull/12563/head
Julien Lebosquain
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
47 additions and
9 deletions
-
src/Avalonia.Controls/ContentControl.cs
-
src/Avalonia.Controls/TransitioningContentControl.cs
-
tests/Avalonia.Controls.UnitTests/TransitioningContentControlTests.cs
|
|
|
@ -40,11 +40,6 @@ namespace Avalonia.Controls |
|
|
|
public static readonly StyledProperty<VerticalAlignment> VerticalContentAlignmentProperty = |
|
|
|
AvaloniaProperty.Register<ContentControl, VerticalAlignment>(nameof(VerticalContentAlignment)); |
|
|
|
|
|
|
|
static ContentControl() |
|
|
|
{ |
|
|
|
ContentProperty.Changed.AddClassHandler<ContentControl>((x, e) => x.ContentChanged(e)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the content to display.
|
|
|
|
/// </summary>
|
|
|
|
@ -100,6 +95,16 @@ namespace Avalonia.Controls |
|
|
|
{ |
|
|
|
return RegisterContentPresenter(presenter); |
|
|
|
} |
|
|
|
|
|
|
|
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) |
|
|
|
{ |
|
|
|
base.OnPropertyChanged(change); |
|
|
|
|
|
|
|
if (change.Property == ContentProperty) |
|
|
|
{ |
|
|
|
ContentChanged(change); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Called when an <see cref="ContentPresenter"/> is registered with the control.
|
|
|
|
|
|
|
|
@ -79,8 +79,12 @@ public class TransitioningContentControl : ContentControl |
|
|
|
|
|
|
|
protected override bool RegisterContentPresenter(ContentPresenter presenter) |
|
|
|
{ |
|
|
|
if (!base.RegisterContentPresenter(presenter) && |
|
|
|
presenter is ContentPresenter p && |
|
|
|
if (base.RegisterContentPresenter(presenter)) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (presenter is ContentPresenter p && |
|
|
|
p.Name == "PART_ContentPresenter2") |
|
|
|
{ |
|
|
|
_presenter2 = p; |
|
|
|
@ -94,12 +98,13 @@ public class TransitioningContentControl : ContentControl |
|
|
|
|
|
|
|
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) |
|
|
|
{ |
|
|
|
base.OnPropertyChanged(change); |
|
|
|
|
|
|
|
if (change.Property == ContentProperty) |
|
|
|
{ |
|
|
|
UpdateContent(true); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
base.OnPropertyChanged(change); |
|
|
|
} |
|
|
|
|
|
|
|
private void UpdateContent(bool withTransition) |
|
|
|
|
|
|
|
@ -183,6 +183,34 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
Assert.Equal("bar", presenter2.Content); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Logical_Children_Should_Not_Be_Duplicated() |
|
|
|
{ |
|
|
|
using var app = Start(); |
|
|
|
var (target, transition) = CreateTarget(""); |
|
|
|
target.PageTransition = null; |
|
|
|
|
|
|
|
var childControl = new Control(); |
|
|
|
target.Content = childControl; |
|
|
|
|
|
|
|
Assert.Equal(1, target.LogicalChildren.Count); |
|
|
|
Assert.Equal(target.LogicalChildren[0], childControl); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void First_Presenter_Should_Register_TCC_As_His_Host() |
|
|
|
{ |
|
|
|
using var app = Start(); |
|
|
|
var (target, transition) = CreateTarget(""); |
|
|
|
target.PageTransition = null; |
|
|
|
|
|
|
|
var childControl = new Control(); |
|
|
|
target.Presenter!.Content = childControl; |
|
|
|
|
|
|
|
Assert.Equal(1, target.LogicalChildren.Count); |
|
|
|
Assert.Equal(target.LogicalChildren[0], childControl); |
|
|
|
} |
|
|
|
|
|
|
|
private static IDisposable Start() |
|
|
|
{ |
|
|
|
return UnitTestApplication.Start( |
|
|
|
|