From a53ccf2b6d8cd3f8bf863ab83fd737c0ccbdab6f Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 9 Dec 2021 17:48:07 -0500 Subject: [PATCH] Merge pull request #7112 from AvaloniaUI/fix-splitview-pane Don't forget to add SplitView.Pane to the logical tree --- src/Avalonia.Controls/SplitView.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/SplitView.cs b/src/Avalonia.Controls/SplitView.cs index 6a0d4e2023..2ea58e6b0d 100644 --- a/src/Avalonia.Controls/SplitView.cs +++ b/src/Avalonia.Controls/SplitView.cs @@ -11,6 +11,7 @@ using System; using System.Reactive.Disposables; using Avalonia.Controls.Presenters; using Avalonia.Controls.Templates; +using Avalonia.LogicalTree; namespace Avalonia.Controls { @@ -168,7 +169,8 @@ namespace Avalonia.Controls CompactPaneLengthProperty.Changed.AddClassHandler((x, v) => x.OnCompactPaneLengthChanged(v)); PanePlacementProperty.Changed.AddClassHandler((x, v) => x.OnPanePlacementChanged(v)); DisplayModeProperty.Changed.AddClassHandler((x, v) => x.OnDisplayModeChanged(v)); - + + PaneProperty.Changed.AddClassHandler((x, e) => x.PaneChanged(e)); } /// @@ -258,6 +260,7 @@ namespace Avalonia.Controls /// /// Gets or sets the Pane for the SplitView /// + [DependsOn(nameof(PaneTemplate))] public object Pane { get => GetValue(PaneProperty); @@ -460,5 +463,18 @@ namespace Avalonia.Controls var mode = (bool)e.NewValue; PseudoClasses.Set(":lightdismiss", mode); } + + private void PaneChanged(AvaloniaPropertyChangedEventArgs e) + { + if (e.OldValue is ILogical oldChild) + { + LogicalChildren.Remove(oldChild); + } + + if (e.NewValue is ILogical newChild) + { + LogicalChildren.Add(newChild); + } + } } }