2023-11-24 17:31:24 +08:00
|
|
|
|
using CPF.Controls;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
2023-11-24 22:58:59 +08:00
|
|
|
|
using System.Linq;
|
2023-11-24 17:31:24 +08:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace CPF.Toolkit.Controls
|
|
|
|
|
{
|
|
|
|
|
public class MdiHost : Panel
|
|
|
|
|
{
|
|
|
|
|
public MdiHost()
|
|
|
|
|
{
|
|
|
|
|
Size = SizeField.Fill;
|
|
|
|
|
Background = "204,204,204";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnPropertyChanged(string propertyName, object oldValue, object newValue, PropertyMetadataAttribute propertyMetadata)
|
|
|
|
|
{
|
|
|
|
|
if (propertyName == nameof(ActualSize))
|
|
|
|
|
{
|
|
|
|
|
foreach (MdiWindow item in this.Children)
|
|
|
|
|
{
|
|
|
|
|
if (item.WindowState == WindowState.Maximized) continue;
|
|
|
|
|
|
|
|
|
|
if (item.MarginLeft.Value + item.ActualSize.Width > this.ActualSize.Width)
|
|
|
|
|
{
|
|
|
|
|
item.MarginLeft = this.ActualSize.Width - item.ActualSize.Width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.MarginTop.Value + item.ActualSize.Height > this.ActualSize.Height)
|
|
|
|
|
{
|
|
|
|
|
item.MarginTop = this.ActualSize.Height - item.ActualSize.Height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
base.OnPropertyChanged(propertyName, oldValue, newValue, propertyMetadata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnUIElementAdded(UIElementAddedEventArgs e)
|
|
|
|
|
{
|
2023-11-24 22:58:59 +08:00
|
|
|
|
e.Element.PreviewMouseDown += Element_PreviewMouseDown; ;
|
2023-11-24 17:31:24 +08:00
|
|
|
|
base.OnUIElementAdded(e);
|
|
|
|
|
}
|
2023-11-24 22:58:59 +08:00
|
|
|
|
|
|
|
|
|
private void Element_PreviewMouseDown(object sender, Input.MouseButtonEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var view = sender as UIElement;
|
|
|
|
|
view.ZIndex = this.Children.Max(x => x.ZIndex) + 1;
|
|
|
|
|
}
|
2023-11-24 17:31:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|