Browse Source

Return true when first presenter register and fix logical children duplicated

pull/12173/head
daniel 3 years ago
parent
commit
f7a584e86e
  1. 16
      src/Avalonia.Controls/ContentControl.cs
  2. 11
      src/Avalonia.Controls/TransitioningContentControl.cs

16
src/Avalonia.Controls/ContentControl.cs

@ -95,6 +95,17 @@ namespace Avalonia.Controls
/// <inheritdoc/>
IAvaloniaList<ILogical> IContentPresenterHost.LogicalChildren => LogicalChildren;
/// <summary>
/// Determine whether <see cref="ContentControl"/> manage his LogicalChildren
///(default behavior) himself, or leaves the management to the inherited control.
/// </summary>
/// <remarks>
/// The default value is false, So the <see cref="ContentControl"/> manages itself,
/// if you want to bypass this behavior and manage LogicalChildren yourself, set
/// the <see cref="BypassLogicalChildrenManangment"/> to true.
/// </remarks>
protected virtual bool BypassLogicalChildrenManangment => false;
/// <inheritdoc/>
bool IContentPresenterHost.RegisterContentPresenter(ContentPresenter presenter)
{
@ -118,6 +129,11 @@ namespace Avalonia.Controls
private void ContentChanged(AvaloniaPropertyChangedEventArgs e)
{
if (BypassLogicalChildrenManangment)
{
return;
}
if (e.OldValue is ILogical oldChild)
{
LogicalChildren.Remove(oldChild);

11
src/Avalonia.Controls/TransitioningContentControl.cs

@ -36,6 +36,9 @@ public class TransitioningContentControl : ContentControl
set => SetValue(PageTransitionProperty, value);
}
/// <inheritdoc/>
protected override bool BypassLogicalChildrenManangment => true;
protected override Size ArrangeOverride(Size finalSize)
{
var result = base.ArrangeOverride(finalSize);
@ -79,8 +82,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;

Loading…
Cancel
Save