mirror of
https://gitee.com/csharpui/CPF.git
synced 2025-07-15 14:04:34 +08:00
1
This commit is contained in:
parent
b79e63da71
commit
507e844275
@ -25,32 +25,13 @@ namespace CPF.Toolkit.Demo
|
|||||||
this.Background = null;
|
this.Background = null;
|
||||||
var frame = this.Children.Add(new WindowFrame(this, new MdiHost
|
var frame = this.Children.Add(new WindowFrame(this, new MdiHost
|
||||||
{
|
{
|
||||||
//Children =
|
Children =
|
||||||
//{
|
|
||||||
// new MdiWindow
|
|
||||||
// {
|
|
||||||
// Title = "test",
|
|
||||||
// Content = new WrapPanel
|
|
||||||
// {
|
|
||||||
// Children =
|
|
||||||
// {
|
|
||||||
// new Button{ Content = "test" ,Width = 100, Height = 35 },
|
|
||||||
// new Button{ Content = "test" ,Width = 100, Height = 35 },
|
|
||||||
// new Button{ Content = "test" ,Width = 100, Height = 35 },
|
|
||||||
// new Button{ Content = "test" ,Width = 100, Height = 35 },
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
.LoopCreate(5,(i) => new MdiWindow
|
|
||||||
{
|
{
|
||||||
Title = $"test{i}",
|
new MdiWindow{ Content = new Grid{ }, Title = "test1"},
|
||||||
Content = new WrapPanel
|
//new MdiWindow{ Content = new Grid{ }, Title = "test2"},
|
||||||
{
|
//new MdiWindow{ Content = new Grid{ }, Title = "test3"},
|
||||||
}
|
},
|
||||||
.LoopCreate(5,k => new Button { Content = $"test{k}",Width = 100, Height = 35 }),
|
}));
|
||||||
})));
|
|
||||||
frame.CaptionBackgrund = "white";
|
frame.CaptionBackgrund = "white";
|
||||||
frame.CaptionForeground = "black";
|
frame.CaptionForeground = "black";
|
||||||
frame.ControlBoxStroke = "black";
|
frame.ControlBoxStroke = "black";
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using CPF.Controls;
|
using CPF.Controls;
|
||||||
|
using CPF.Drawing;
|
||||||
|
using CPF.Platform;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@ -7,46 +9,131 @@ using System.Text;
|
|||||||
|
|
||||||
namespace CPF.Toolkit.Controls
|
namespace CPF.Toolkit.Controls
|
||||||
{
|
{
|
||||||
public class MdiHost : Panel
|
public class MdiHost : Grid
|
||||||
{
|
{
|
||||||
public MdiHost()
|
public MdiHost()
|
||||||
{
|
{
|
||||||
Size = SizeField.Fill;
|
this.TaskBarList = new Collection<UIElement>();
|
||||||
Background = "204,204,204";
|
this.Size = SizeField.Fill;
|
||||||
|
this.Background = "204,204,204";
|
||||||
|
base.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star });
|
||||||
|
base.RowDefinitions.Add(new RowDefinition { Height = "35", MaxHeight = 35 });
|
||||||
|
|
||||||
|
base.Children.Add(this.host);
|
||||||
|
var taskBar = base.Children.Add(new ListBox
|
||||||
|
{
|
||||||
|
Size = SizeField.Fill,
|
||||||
|
Background = "white",
|
||||||
|
BorderFill = new SolidColorFill { Color = Color.Silver },
|
||||||
|
BorderThickness = new Thickness(0, 1, 0, 0),
|
||||||
|
BorderType = BorderType.BorderThickness,
|
||||||
|
ItemsPanel = new StackPanel { Orientation = Orientation.Horizontal },
|
||||||
|
ItemTemplate = new ListBoxItem
|
||||||
|
{
|
||||||
|
Height = "100%",
|
||||||
|
Width = 100,
|
||||||
|
MarginRight = 1,
|
||||||
|
FontSize = 16f,
|
||||||
|
BorderFill = "Silver",
|
||||||
|
BorderThickness = new Thickness(0, 0, 1, 0),
|
||||||
|
BorderType = BorderType.BorderThickness,
|
||||||
|
[nameof(ListBoxItem.Content)] = new BindingDescribe("Title")
|
||||||
|
},
|
||||||
|
Items = this.TaskBarList,
|
||||||
|
[nameof(ListBox.SelectedValue)] = new BindingDescribe(this, nameof(this.SelectWindow), BindingMode.TwoWay),
|
||||||
|
}, row: 1);
|
||||||
|
this.host.PropertyChanged += Host_PropertyChanged;
|
||||||
|
this.host.UIElementAdded += Host_UIElementAdded;
|
||||||
|
this.host.UIElementRemoved += Host_UIElementRemoved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readonly Panel host = new Panel { Size = SizeField.Fill };
|
||||||
|
Collection<UIElement> TaskBarList { get => GetValue<Collection<UIElement>>(); set => SetValue(value); }
|
||||||
|
public new UIElementCollection Children => host.Children;
|
||||||
|
UIElement SelectWindow { get => GetValue<UIElement>(); set => SetValue(value); }
|
||||||
|
|
||||||
protected override void OnPropertyChanged(string propertyName, object oldValue, object newValue, PropertyMetadataAttribute propertyMetadata)
|
protected override void OnPropertyChanged(string propertyName, object oldValue, object newValue, PropertyMetadataAttribute propertyMetadata)
|
||||||
{
|
{
|
||||||
if (propertyName == nameof(ActualSize))
|
if (propertyName == nameof(this.SelectWindow))
|
||||||
{
|
{
|
||||||
foreach (MdiWindow item in this.Children)
|
this.Topping(this.SelectWindow);
|
||||||
{
|
|
||||||
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);
|
base.OnPropertyChanged(propertyName, oldValue, newValue, propertyMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnUIElementAdded(UIElementAddedEventArgs e)
|
private void Host_PropertyChanged(object sender, CPFPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
e.Element.PreviewMouseDown += Element_PreviewMouseDown; ;
|
if (e.PropertyName.Or(nameof(ActualSize), nameof(Size), nameof(Width), nameof(Height)))
|
||||||
base.OnUIElementAdded(e);
|
{
|
||||||
|
foreach (MdiWindow mdi in this.host.Children)
|
||||||
|
{
|
||||||
|
if (mdi.WindowState == WindowState.Maximized) continue;
|
||||||
|
|
||||||
|
if (mdi.MarginLeft.Value + mdi.ActualSize.Width > this.ActualSize.Width)
|
||||||
|
{
|
||||||
|
mdi.MarginLeft = this.ActualSize.Width - mdi.ActualSize.Width;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mdi.MarginTop.Value + mdi.ActualSize.Height > this.ActualSize.Height)
|
||||||
|
{
|
||||||
|
mdi.MarginTop = this.ActualSize.Height - mdi.ActualSize.Height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Host_UIElementRemoved(object sender, UIElementRemovedEventArgs e)
|
||||||
|
{
|
||||||
|
e.Element.PropertyChanged -= Element_PropertyChanged;
|
||||||
|
e.Element.PreviewMouseDown -= Element_PreviewMouseDown;
|
||||||
|
this.TaskBarList.Remove(e.Element);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Host_UIElementAdded(object sender, UIElementAddedEventArgs e)
|
||||||
|
{
|
||||||
|
var view = e.Element as MdiWindow;
|
||||||
|
view.PropertyChanged += Element_PropertyChanged;
|
||||||
|
view.PreviewMouseDown += Element_PreviewMouseDown;
|
||||||
|
this.TaskBarList.Add(view);
|
||||||
|
e.Element.ZIndex = this.host.Children.Max(x => x.ZIndex) + 1;
|
||||||
|
this.Topping(e.Element);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Element_PreviewMouseDown(object sender, Input.MouseButtonEventArgs e)
|
private void Element_PreviewMouseDown(object sender, Input.MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
var view = sender as UIElement;
|
var ele = (UIElement)sender;
|
||||||
view.ZIndex = this.Children.Max(x => x.ZIndex) + 1;
|
this.Topping(ele);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Element_PropertyChanged(object sender, CPFPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var view = sender as MdiWindow;
|
||||||
|
switch (e.PropertyName)
|
||||||
|
{
|
||||||
|
case nameof(MdiWindow.WindowState):
|
||||||
|
if ((WindowState)e.NewValue == WindowState.Minimized)
|
||||||
|
{
|
||||||
|
this.SelectWindow = this.host.Children.FindLast(x => x.Visibility == Visibility.Visible);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case nameof(ZIndex):
|
||||||
|
this.SelectWindow = view;
|
||||||
|
this.SelectWindow.Visibility = Visibility.Visible;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Topping(UIElement ele)
|
||||||
|
{
|
||||||
|
if (ele == null) return;
|
||||||
|
var index = this.host.Children.Max(x => x.ZIndex);
|
||||||
|
if (ele.ZIndex == index)
|
||||||
|
{
|
||||||
|
ele.Visibility = Visibility.Visible;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ele.ZIndex = index + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,9 @@ namespace CPF.Toolkit.Controls
|
|||||||
{
|
{
|
||||||
public class MdiWindow : Control
|
public class MdiWindow : Control
|
||||||
{
|
{
|
||||||
[PropertyMetadata(typeof(WindowState), "Normal")]
|
[PropertyMetadata(typeof(WindowState), "0")]
|
||||||
public WindowState WindowState { get => GetValue<WindowState>(); set => SetValue(value); }
|
public WindowState WindowState { get => GetValue<WindowState>(); set => SetValue(value); }
|
||||||
|
[PropertyMetadata("title")]
|
||||||
public string Title { get => GetValue<string>(); set => SetValue(value); }
|
public string Title { get => GetValue<string>(); set => SetValue(value); }
|
||||||
public UIElement Content { get => GetValue<UIElement>(); set => SetValue(value); }
|
public UIElement Content { get => GetValue<UIElement>(); set => SetValue(value); }
|
||||||
[PropertyMetadata(true)]
|
[PropertyMetadata(true)]
|
||||||
@ -32,6 +33,9 @@ namespace CPF.Toolkit.Controls
|
|||||||
[UIPropertyMetadata((byte)5, UIPropertyOptions.AffectsMeasure)]
|
[UIPropertyMetadata((byte)5, UIPropertyOptions.AffectsMeasure)]
|
||||||
public byte ShadowBlur { get { return GetValue<byte>(); } set { SetValue(value); } }
|
public byte ShadowBlur { get { return GetValue<byte>(); } set { SetValue(value); } }
|
||||||
|
|
||||||
|
public event EventHandler<ClosingEventArgs> Closing;
|
||||||
|
|
||||||
|
WindowState oldState;
|
||||||
SizeField normalSize = new SizeField(500, 500);
|
SizeField normalSize = new SizeField(500, 500);
|
||||||
Point normalPos = new Point(0, 0);
|
Point normalPos = new Point(0, 0);
|
||||||
protected override void InitializeComponent()
|
protected override void InitializeComponent()
|
||||||
@ -208,7 +212,11 @@ namespace CPF.Toolkit.Controls
|
|||||||
StrokeStyle = "2",
|
StrokeStyle = "2",
|
||||||
},
|
},
|
||||||
Commands = { { nameof(Button.Click),(s,e) => this.WindowState = WindowState.Maximized } },
|
Commands = { { nameof(Button.Click),(s,e) => this.WindowState = WindowState.Maximized } },
|
||||||
[nameof(Visibility)] = new BindingDescribe(this,nameof(WindowState),BindingMode.OneWay,a => ((WindowState)a).Or(WindowState.Maximized,WindowState.FullScreen) ? Visibility.Collapsed : Visibility.Visible),
|
[nameof(Visibility)] = new BindingDescribe(this,
|
||||||
|
nameof(WindowState),
|
||||||
|
BindingMode.OneWay,
|
||||||
|
a => ((WindowState)a).Or(WindowState.Maximized,WindowState.FullScreen)
|
||||||
|
? Visibility.Collapsed : Visibility.Visible),
|
||||||
},
|
},
|
||||||
new SystemButton
|
new SystemButton
|
||||||
{
|
{
|
||||||
@ -244,7 +252,12 @@ namespace CPF.Toolkit.Controls
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Commands = { { nameof(Button.Click),(s,e) => this.WindowState = WindowState.Normal } },
|
Commands = { { nameof(Button.Click),(s,e) => this.WindowState = WindowState.Normal } },
|
||||||
[nameof(Visibility)] = new BindingDescribe(this,nameof(WindowState),BindingMode.OneWay,a => ((WindowState)a).Or( WindowState.Normal, WindowState.Minimized) ? Visibility.Collapsed : Visibility.Visible)
|
[nameof(Visibility)] = new BindingDescribe(this,
|
||||||
|
nameof(WindowState),
|
||||||
|
BindingMode.OneWay,
|
||||||
|
a => ((WindowState)a).Or( WindowState.Normal, WindowState.Minimized)
|
||||||
|
? Visibility.Collapsed :
|
||||||
|
Visibility.Visible)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -277,6 +290,21 @@ namespace CPF.Toolkit.Controls
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Commands =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
nameof(Button.Click),(ss,ee) =>
|
||||||
|
{
|
||||||
|
var e = new ClosingEventArgs();
|
||||||
|
this.Closing?.Invoke(this,e);
|
||||||
|
if (!e.Cancel)
|
||||||
|
{
|
||||||
|
this.Visibility = Visibility.Collapsed;
|
||||||
|
this.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
[nameof(Visibility)] = new BindingDescribe(this,nameof(this.CloseBox),BindingMode.OneWay,a=>(bool)a?Visibility.Visible: Visibility.Collapsed)
|
[nameof(Visibility)] = new BindingDescribe(this,nameof(this.CloseBox),BindingMode.OneWay,a=>(bool)a?Visibility.Visible: Visibility.Collapsed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,7 +317,7 @@ namespace CPF.Toolkit.Controls
|
|||||||
nameof(Thumb.DragDelta),
|
nameof(Thumb.DragDelta),
|
||||||
(s,e) =>
|
(s,e) =>
|
||||||
{
|
{
|
||||||
if (this.WindowState.Or(WindowState.Normal, WindowState.Minimized))
|
if (this.WindowState.Or(WindowState.Normal))
|
||||||
{
|
{
|
||||||
var arge = e as DragDeltaEventArgs;
|
var arge = e as DragDeltaEventArgs;
|
||||||
this.MarginLeft += arge.HorizontalChange;
|
this.MarginLeft += arge.HorizontalChange;
|
||||||
@ -323,8 +351,10 @@ namespace CPF.Toolkit.Controls
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[nameof(Border.ShadowBlur)] = new BindingDescribe(this, nameof(WindowState), BindingMode.OneWay, a => ((WindowState)a).Or(WindowState.Maximized, WindowState.FullScreen) ? 0 : ShadowBlur),
|
[nameof(Border.ShadowBlur)] = new BindingDescribe(this,
|
||||||
[nameof(Border.ShadowBlur)] = new BindingDescribe(this, nameof(ShadowBlur), BindingMode.OneWay, a => ((WindowState)a).Or(WindowState.Maximized, WindowState.FullScreen) ? 0 : (byte)a),
|
nameof(WindowState),
|
||||||
|
BindingMode.OneWay,
|
||||||
|
a => ((WindowState)a).Or(WindowState.Maximized, WindowState.FullScreen,WindowState.Minimized) ? 0 : ShadowBlur),
|
||||||
});
|
});
|
||||||
|
|
||||||
this.Content.Margin = "0";
|
this.Content.Margin = "0";
|
||||||
@ -345,8 +375,8 @@ namespace CPF.Toolkit.Controls
|
|||||||
this.MarginTop = this.normalPos.Y;
|
this.MarginTop = this.normalPos.Y;
|
||||||
break;
|
break;
|
||||||
case WindowState.Minimized:
|
case WindowState.Minimized:
|
||||||
this.Width = this.MinWidth;
|
this.Visibility = Visibility.Collapsed;
|
||||||
this.Height = this.MinHeight;
|
this.oldState = (WindowState)oldValue;
|
||||||
break;
|
break;
|
||||||
case WindowState.Maximized:
|
case WindowState.Maximized:
|
||||||
case WindowState.FullScreen:
|
case WindowState.FullScreen:
|
||||||
@ -368,11 +398,10 @@ namespace CPF.Toolkit.Controls
|
|||||||
this.normalSize = this.Size;
|
this.normalSize = this.Size;
|
||||||
break;
|
break;
|
||||||
case WindowState.Minimized:
|
case WindowState.Minimized:
|
||||||
this.Width = this.MinWidth;
|
//this.Width = this.MinWidth;
|
||||||
this.Height = this.MinHeight;
|
//this.Height = this.MinHeight;
|
||||||
break;
|
break;
|
||||||
case WindowState.Maximized:
|
case WindowState.Maximized:
|
||||||
break;
|
|
||||||
case WindowState.FullScreen:
|
case WindowState.FullScreen:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -396,5 +425,15 @@ namespace CPF.Toolkit.Controls
|
|||||||
|
|
||||||
base.OnPropertyChanged(propertyName, oldValue, newValue, propertyMetadata);
|
base.OnPropertyChanged(propertyName, oldValue, newValue, propertyMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return this.Title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReWindowState()
|
||||||
|
{
|
||||||
|
this.WindowState = this.oldState;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user