fix(docking): improve DockDocument nullability and DockGroup property reactivity

This commit is contained in:
2026-03-28 21:56:05 +09:00
parent acbf315e8f
commit 332a940993
2 changed files with 25 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ using Microsoft.UI.Xaml.Controls;
namespace Ghost.Editor.View.Controls.Docking; namespace Ghost.Editor.View.Controls.Docking;
public class DockDocument : DockModule public partial class DockDocument : DockModule
{ {
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(
nameof(Title), typeof(string), typeof(DockDocument), new PropertyMetadata(string.Empty)); 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( public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(
nameof(Content), typeof(object), typeof(DockDocument), new PropertyMetadata(null)); 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); set => SetValue(TitleProperty, value);
} }
public object Content public object? Content
{ {
get => GetValue(ContentProperty); get => GetValue(ContentProperty);
set => SetValue(ContentProperty, value); set => SetValue(ContentProperty, value);

View File

@@ -1,11 +1,14 @@
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
namespace Ghost.Editor.View.Controls.Docking; namespace Ghost.Editor.View.Controls.Docking;
[TemplatePart(Name = "PART_TabView", Type = typeof(TabView))] [TemplatePart(Name = PART_TabView, Type = typeof(TabView))]
public class DockGroup : DockContainer public partial class DockGroup : DockContainer
{ {
private const string PART_TabView = "PART_TabView";
private TabView? _tabView; private TabView? _tabView;
public DockGroup() public DockGroup()
@@ -16,7 +19,7 @@ public class DockGroup : DockContainer
protected override void OnApplyTemplate() protected override void OnApplyTemplate()
{ {
base.OnApplyTemplate(); base.OnApplyTemplate();
_tabView = GetTemplateChild("PART_TabView") as TabView; _tabView = GetTemplateChild(PART_TabView) as TabView;
UpdateTabs(); UpdateTabs();
} }
@@ -36,10 +39,23 @@ public class DockGroup : DockContainer
{ {
var tabItem = new TabViewItem var tabItem = new TabViewItem
{ {
Header = doc.Title,
Content = doc.Content,
Tag = doc 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); _tabView.TabItems.Add(tabItem);
} }
} }