From 332a94099380f397f60112fa5812c5092a1ea8c1 Mon Sep 17 00:00:00 2001 From: Misaki Date: Sat, 28 Mar 2026 21:56:05 +0900 Subject: [PATCH] fix(docking): improve DockDocument nullability and DockGroup property reactivity --- .../View/Controls/Docking/DockDocument.cs | 8 +++--- .../View/Controls/Docking/DockGroup.cs | 26 +++++++++++++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockDocument.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockDocument.cs index 28d1abd..9454c2e 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockDocument.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockDocument.cs @@ -3,7 +3,7 @@ using Microsoft.UI.Xaml.Controls; namespace Ghost.Editor.View.Controls.Docking; -public class DockDocument : DockModule +public partial class DockDocument : DockModule { public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( nameof(Title), typeof(string), typeof(DockDocument), new PropertyMetadata(string.Empty)); @@ -11,13 +11,13 @@ public class DockDocument : DockModule public static readonly DependencyProperty ContentProperty = DependencyProperty.Register( nameof(Content), typeof(object), typeof(DockDocument), new PropertyMetadata(null)); - public string Title + public string? Title { - get => (string)GetValue(TitleProperty); + get => (string?)GetValue(TitleProperty); set => SetValue(TitleProperty, value); } - public object Content + public object? Content { get => GetValue(ContentProperty); set => SetValue(ContentProperty, value); diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs index dd2ca76..6d4d7c9 100644 --- a/src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs @@ -1,11 +1,14 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Data; + namespace Ghost.Editor.View.Controls.Docking; -[TemplatePart(Name = "PART_TabView", Type = typeof(TabView))] -public class DockGroup : DockContainer +[TemplatePart(Name = PART_TabView, Type = typeof(TabView))] +public partial class DockGroup : DockContainer { + private const string PART_TabView = "PART_TabView"; private TabView? _tabView; public DockGroup() @@ -16,7 +19,7 @@ public class DockGroup : DockContainer protected override void OnApplyTemplate() { base.OnApplyTemplate(); - _tabView = GetTemplateChild("PART_TabView") as TabView; + _tabView = GetTemplateChild(PART_TabView) as TabView; UpdateTabs(); } @@ -36,10 +39,23 @@ public class DockGroup : DockContainer { var tabItem = new TabViewItem { - Header = doc.Title, - Content = doc.Content, Tag = doc }; + + tabItem.SetBinding(TabViewItem.HeaderProperty, new Binding + { + Source = doc, + Path = new PropertyPath(nameof(DockDocument.Title)), + Mode = BindingMode.OneWay + }); + + tabItem.SetBinding(ContentControl.ContentProperty, new Binding + { + Source = doc, + Path = new PropertyPath(nameof(DockDocument.Content)), + Mode = BindingMode.OneWay + }); + _tabView.TabItems.Add(tabItem); } }