Добавлен проект UI

This commit is contained in:
2026-01-07 22:33:42 +03:00
parent b6de0543b7
commit ca5d912c9c
21 changed files with 1188 additions and 4 deletions

View File

@@ -0,0 +1,83 @@
using Lattice.Core.Models;
using Lattice.UI.DragDrop;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace Lattice.UI.Controls;
/// <summary>
/// Представляет визуальный контейнер для содержимого (панели или документа) в системе Lattice.
/// </summary>
[TemplatePart(Name = "HeaderPresenter", Type = typeof(FrameworkElement))]
[TemplatePart(Name = "ContentPresenter", Type = typeof(ContentPresenter))]
[TemplatePart(Name = "PART_CloseButton", Type = typeof(Button))] // Добавлено для ясности
public class LatticePane : ContentControl
{
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register(nameof(Title), typeof(string), typeof(LatticePane), new PropertyMetadata(string.Empty));
public static readonly DependencyProperty HeaderContentProperty =
DependencyProperty.Register(nameof(HeaderContent), typeof(object), typeof(LatticePane), new PropertyMetadata(null));
/// <summary>
/// Событие, возникающее при нажатии на кнопку закрытия в шаблоне.
/// </summary>
public event RoutedEventHandler? CloseClick;
public string Title
{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}
public object HeaderContent
{
get => GetValue(HeaderContentProperty);
set => SetValue(HeaderContentProperty, value);
}
public LatticePane()
{
this.DefaultStyleKey = typeof(LatticePane);
}
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
// Логика кнопки закрытия
if (GetTemplateChild("PART_CloseButton") is Button closeButton)
{
closeButton.Click -= OnCloseButtonClick; // Защита от двойной подписки
closeButton.Click += OnCloseButtonClick;
}
// Логика перетаскивания (Drag-and-Drop)
if (GetTemplateChild("HeaderPresenter") is FrameworkElement header)
{
this.Loaded += (s, e) =>
{
var host = FindParentHost(this);
if (host != null && this.DataContext is LayoutNode node)
{
var handler = new DockTabHandler(host);
handler.Attach(header, node);
}
};
}
}
private void OnCloseButtonClick(object sender, RoutedEventArgs e)
{
CloseClick?.Invoke(this, e);
}
private LatticeDockHost? FindParentHost(DependencyObject child)
{
var parent = Microsoft.UI.Xaml.Media.VisualTreeHelper.GetParent(child);
if (parent == null) return null;
if (parent is LatticeDockHost host) return host;
return FindParentHost(parent);
}
}