From 5f3ba2008f35cf0150e03a5089230e5192ceb790 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Thu, 22 Oct 2020 17:26:41 +0100 Subject: [PATCH] fix splitview by making it use contentpresenter, templates and hve its children be logical children. --- src/Avalonia.Controls/ApiCompatBaseline.txt | 8 ++- src/Avalonia.Controls/SplitView.cs | 54 +++++++++++++-------- src/Avalonia.Dialogs/ApiCompatBaseline.txt | 1 + src/Avalonia.Themes.Default/SplitView.xaml | 8 +-- src/Avalonia.Themes.Fluent/SplitView.xaml | 8 +-- 5 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 src/Avalonia.Dialogs/ApiCompatBaseline.txt diff --git a/src/Avalonia.Controls/ApiCompatBaseline.txt b/src/Avalonia.Controls/ApiCompatBaseline.txt index af88c569a6..16c801201c 100644 --- a/src/Avalonia.Controls/ApiCompatBaseline.txt +++ b/src/Avalonia.Controls/ApiCompatBaseline.txt @@ -8,6 +8,12 @@ MembersMustExist : Member 'public void Avalonia.Controls.ListBox.Selection.set(A TypesMustExist : Type 'Avalonia.Controls.SelectionModel' does not exist in the implementation but it does exist in the contract. TypesMustExist : Type 'Avalonia.Controls.SelectionModelChildrenRequestedEventArgs' does not exist in the implementation but it does exist in the contract. TypesMustExist : Type 'Avalonia.Controls.SelectionModelSelectionChangedEventArgs' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public Avalonia.StyledProperty Avalonia.StyledProperty Avalonia.Controls.SplitView.ContentProperty' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public Avalonia.StyledProperty Avalonia.StyledProperty Avalonia.Controls.SplitView.PaneProperty' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public Avalonia.Controls.IControl Avalonia.Controls.SplitView.Content.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public void Avalonia.Controls.SplitView.Content.set(Avalonia.Controls.IControl)' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public Avalonia.Controls.IControl Avalonia.Controls.SplitView.Pane.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public void Avalonia.Controls.SplitView.Pane.set(Avalonia.Controls.IControl)' does not exist in the implementation but it does exist in the contract. MembersMustExist : Member 'public Avalonia.DirectProperty Avalonia.DirectProperty Avalonia.Controls.TreeView.SelectionProperty' does not exist in the implementation but it does exist in the contract. MembersMustExist : Member 'public Avalonia.Interactivity.RoutedEvent Avalonia.Interactivity.RoutedEvent Avalonia.Controls.TreeView.SelectionChangedEvent' does not exist in the implementation but it does exist in the contract. MembersMustExist : Member 'public Avalonia.Controls.ISelectionModel Avalonia.Controls.TreeView.Selection.get()' does not exist in the implementation but it does exist in the contract. @@ -17,4 +23,4 @@ InterfacesShouldHaveSameMembers : Interface member 'public System.String[] Avalo MembersMustExist : Member 'public Avalonia.DirectProperty Avalonia.DirectProperty Avalonia.Controls.Primitives.SelectingItemsControl.SelectionProperty' does not exist in the implementation but it does exist in the contract. MembersMustExist : Member 'protected Avalonia.Controls.ISelectionModel Avalonia.Controls.Primitives.SelectingItemsControl.Selection.get()' does not exist in the implementation but it does exist in the contract. MembersMustExist : Member 'protected void Avalonia.Controls.Primitives.SelectingItemsControl.Selection.set(Avalonia.Controls.ISelectionModel)' does not exist in the implementation but it does exist in the contract. -Total Issues: 18 +Total Issues: 24 diff --git a/src/Avalonia.Controls/SplitView.cs b/src/Avalonia.Controls/SplitView.cs index 8267efc466..4500d52484 100644 --- a/src/Avalonia.Controls/SplitView.cs +++ b/src/Avalonia.Controls/SplitView.cs @@ -9,6 +9,8 @@ using Avalonia.Platform; using Avalonia.VisualTree; using System; using System.Reactive.Disposables; +using Avalonia.Controls.Presenters; +using Avalonia.Controls.Templates; namespace Avalonia.Controls { @@ -78,7 +80,7 @@ namespace Avalonia.Controls [PseudoClasses(":compactoverlay", ":compactinline", ":overlay", ":inline")] [PseudoClasses(":left", ":right")] [PseudoClasses(":lightdismiss")] - public class SplitView : TemplatedControl + public class SplitView : ContentControl { /* Pseudo classes & combos @@ -87,12 +89,6 @@ namespace Avalonia.Controls :left :right */ - /// - /// Defines the property - /// - public static readonly StyledProperty ContentProperty = - AvaloniaProperty.Register(nameof(Content)); - /// /// Defines the property /// @@ -133,8 +129,14 @@ namespace Avalonia.Controls /// /// Defines the property /// - public static readonly StyledProperty PaneProperty = - AvaloniaProperty.Register(nameof(Pane)); + public static readonly StyledProperty PaneProperty = + AvaloniaProperty.Register(nameof(Pane)); + + /// + /// Defines the property. + /// + public static readonly StyledProperty PaneTemplateProperty = + AvaloniaProperty.Register(nameof(PaneTemplate)); /// /// Defines the property @@ -166,16 +168,7 @@ 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)); - } - - /// - /// Gets or sets the content of the SplitView - /// - [Content] - public IControl Content - { - get => GetValue(ContentProperty); - set => SetValue(ContentProperty, value); + } /// @@ -265,11 +258,20 @@ namespace Avalonia.Controls /// /// Gets or sets the Pane for the SplitView /// - public IControl Pane + public object Pane { get => GetValue(PaneProperty); set => SetValue(PaneProperty, value); } + + /// + /// Gets or sets the data template used to display the header content of the control. + /// + public IDataTemplate? PaneTemplate + { + get => GetValue(PaneTemplateProperty); + set => SetValue(PaneTemplateProperty, value); + } /// /// Gets or sets whether WinUI equivalent LightDismissOverlayMode is enabled @@ -312,6 +314,18 @@ namespace Avalonia.Controls /// public event EventHandler PaneOpening; + protected override bool RegisterContentPresenter(IContentPresenter presenter) + { + var result = base.RegisterContentPresenter(presenter); + + if (presenter.Name == "PART_PanePresenter") + { + return true; + } + + return result; + } + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); diff --git a/src/Avalonia.Dialogs/ApiCompatBaseline.txt b/src/Avalonia.Dialogs/ApiCompatBaseline.txt new file mode 100644 index 0000000000..fcc74cf864 --- /dev/null +++ b/src/Avalonia.Dialogs/ApiCompatBaseline.txt @@ -0,0 +1 @@ +Total Issues: 0 diff --git a/src/Avalonia.Themes.Default/SplitView.xaml b/src/Avalonia.Themes.Default/SplitView.xaml index 2fb59cdbc4..18da3edb46 100644 --- a/src/Avalonia.Themes.Default/SplitView.xaml +++ b/src/Avalonia.Themes.Default/SplitView.xaml @@ -32,12 +32,12 @@ ClipToBounds="True" HorizontalAlignment="Left" ZIndex="100"> - + - + @@ -106,14 +106,14 @@ ClipToBounds="True" HorizontalAlignment="Right" ZIndex="100"> - + - + diff --git a/src/Avalonia.Themes.Fluent/SplitView.xaml b/src/Avalonia.Themes.Fluent/SplitView.xaml index 71e92459f1..7d6f7a9b9a 100644 --- a/src/Avalonia.Themes.Fluent/SplitView.xaml +++ b/src/Avalonia.Themes.Fluent/SplitView.xaml @@ -32,12 +32,12 @@ ClipToBounds="True" HorizontalAlignment="Left" ZIndex="100"> - + - + @@ -106,14 +106,14 @@ ClipToBounds="True" HorizontalAlignment="Right" ZIndex="100"> - + - +