feat(docking): add DockDocument and DockGroup
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
using Microsoft.UI.Xaml;
|
||||||
|
using Microsoft.UI.Xaml.Controls;
|
||||||
|
|
||||||
|
namespace Ghost.Editor.View.Controls.Docking;
|
||||||
|
|
||||||
|
public class DockDocument : DockModule
|
||||||
|
{
|
||||||
|
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(
|
||||||
|
nameof(Title), typeof(string), typeof(DockDocument), new PropertyMetadata(string.Empty));
|
||||||
|
|
||||||
|
public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(
|
||||||
|
nameof(Content), typeof(object), typeof(DockDocument), new PropertyMetadata(null));
|
||||||
|
|
||||||
|
public string Title
|
||||||
|
{
|
||||||
|
get => (string)GetValue(TitleProperty);
|
||||||
|
set => SetValue(TitleProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public object Content
|
||||||
|
{
|
||||||
|
get => GetValue(ContentProperty);
|
||||||
|
set => SetValue(ContentProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DockDocument()
|
||||||
|
{
|
||||||
|
DefaultStyleKey = typeof(DockDocument);
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs
Normal file
47
src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using Microsoft.UI.Xaml;
|
||||||
|
using Microsoft.UI.Xaml.Controls;
|
||||||
|
|
||||||
|
namespace Ghost.Editor.View.Controls.Docking;
|
||||||
|
|
||||||
|
[TemplatePart(Name = "PART_TabView", Type = typeof(TabView))]
|
||||||
|
public class DockGroup : DockContainer
|
||||||
|
{
|
||||||
|
private TabView? _tabView;
|
||||||
|
|
||||||
|
public DockGroup()
|
||||||
|
{
|
||||||
|
DefaultStyleKey = typeof(DockGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnApplyTemplate()
|
||||||
|
{
|
||||||
|
base.OnApplyTemplate();
|
||||||
|
_tabView = GetTemplateChild("PART_TabView") as TabView;
|
||||||
|
UpdateTabs();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnChildrenUpdated()
|
||||||
|
{
|
||||||
|
UpdateTabs();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateTabs()
|
||||||
|
{
|
||||||
|
if (_tabView == null) return;
|
||||||
|
|
||||||
|
_tabView.TabItems.Clear();
|
||||||
|
foreach (var child in Children)
|
||||||
|
{
|
||||||
|
if (child is DockDocument doc)
|
||||||
|
{
|
||||||
|
var tabItem = new TabViewItem
|
||||||
|
{
|
||||||
|
Header = doc.Title,
|
||||||
|
Content = doc.Content,
|
||||||
|
Tag = doc
|
||||||
|
};
|
||||||
|
_tabView.TabItems.Add(tabItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.xaml
Normal file
22
src/Editor/Ghost.Editor/View/Controls/Docking/DockGroup.xaml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<ResourceDictionary
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="using:Ghost.Editor.View.Controls.Docking">
|
||||||
|
|
||||||
|
<Style TargetType="local:DockGroup">
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="local:DockGroup">
|
||||||
|
<Grid>
|
||||||
|
<TabView x:Name="PART_TabView"
|
||||||
|
IsAddTabButtonVisible="False"
|
||||||
|
CanDragTabs="True"
|
||||||
|
CanReorderTabs="True"
|
||||||
|
AllowDrop="True">
|
||||||
|
</TabView>
|
||||||
|
</Grid>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
</ResourceDictionary>
|
||||||
Reference in New Issue
Block a user