This commit is contained in:
Sakura 2023-11-24 20:01:57 +08:00
parent db457dac7b
commit 235e8ec59e

View File

@ -19,14 +19,18 @@ namespace CPF.Toolkit.Controls
{ {
public class MdiWindow : Control public class MdiWindow : Control
{ {
[PropertyMetadata(typeof(WindowState), "Normal")]
public WindowState WindowState { get => GetValue<WindowState>(); set => SetValue(value); } public WindowState WindowState { get => GetValue<WindowState>(); set => SetValue(value); }
public Image Icon { get => GetValue<Image>(); set => SetValue(value); }
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)]
public bool MaximizeBox { get { return GetValue<bool>(); } set { SetValue(value); } } public bool MaximizeBox { get { return GetValue<bool>(); } set { SetValue(value); } }
[PropertyMetadata(true)] [PropertyMetadata(true)]
public bool MinimizeBox { get { return GetValue<bool>(); } set { SetValue(value); } } public bool MinimizeBox { get { return GetValue<bool>(); } set { SetValue(value); } }
[PropertyMetadata(true)]
public bool CloseBox { get { return GetValue<bool>(); } set { SetValue(value); } }
[UIPropertyMetadata((byte)5, UIPropertyOptions.AffectsMeasure)]
public byte ShadowBlur { get { return GetValue<byte>(); } set { SetValue(value); } }
SizeField normalSize = new SizeField(500, 500); SizeField normalSize = new SizeField(500, 500);
Point normalPos = new Point(0, 0); Point normalPos = new Point(0, 0);
@ -34,13 +38,25 @@ namespace CPF.Toolkit.Controls
{ {
var bar = (ViewFill)"154,180,208"; var bar = (ViewFill)"154,180,208";
this.Size = normalSize; this.Size = normalSize;
this.Background = "white"; this.Background = null;
this.MarginLeft = 0; this.MarginLeft = 0;
this.MarginTop = 0; this.MarginTop = 0;
this.MinWidth = 150; this.MinWidth = 200;
this.MinHeight = 50; this.MinHeight = 70;
this.ClipToBounds = true; this.ClipToBounds = true;
base.Children.Add(new Grid this.Children.Add(new Border
{
Size = SizeField.Fill,
Background = "#fff",
BorderType = BorderType.BorderStroke,
BorderStroke = new Stroke(0),
ShadowBlur = ShadowBlur,
ShadowColor = Color.FromRgba(0, 0, 0, 150),
Child = new Decorator
{
Size = SizeField.Fill,
ClipToBounds = true,
Child = new Grid
{ {
Size = SizeField.Fill, Size = SizeField.Fill,
ColumnDefinitions = ColumnDefinitions =
@ -86,6 +102,7 @@ namespace CPF.Toolkit.Controls
Size = "5,100%", Size = "5,100%",
Background = bar, Background = bar,
Cursor = Cursors.SizeWestEast, Cursor = Cursors.SizeWestEast,
IsEnabled = false,
Attacheds = { { Grid.ColumnIndex,0 } ,{ Grid.RowSpan,4 } }, Attacheds = { { Grid.ColumnIndex,0 } ,{ Grid.RowSpan,4 } },
Commands = Commands =
{ {
@ -159,15 +176,25 @@ namespace CPF.Toolkit.Controls
Size = new SizeField(30,"100%"), Size = new SizeField(30,"100%"),
Content = new Line Content = new Line
{ {
//MarginTop = 5,
MarginLeft = "auto", MarginLeft = "auto",
StartPoint = new Point(1,13), StartPoint = new Point(1,13),
EndPoint = new Point(14,13), EndPoint = new Point(14,13),
StrokeStyle = "2", StrokeStyle = "2",
IsAntiAlias = true, IsAntiAlias = true,
StrokeFill = "black" StrokeFill = "black"
},
Bindings=
{
{
nameof(Visibility),
nameof(MinimizeBox),
this,
BindingMode.OneWay,
a=>(bool)a?Visibility.Visible: Visibility.Collapsed
} }
}, },
Commands = { { nameof(Button.Click),(s,e) => this.WindowState = WindowState.Minimized } },
},
new Panel new Panel
{ {
Height = "100%", Height = "100%",
@ -193,10 +220,7 @@ namespace CPF.Toolkit.Controls
MarginTop = 5, MarginTop = 5,
StrokeStyle = "2", StrokeStyle = "2",
}, },
Commands = Commands = { { nameof(Button.Click),(s,e) => this.WindowState = WindowState.Maximized } },
{
{ nameof(Button.Click),(s,e) => this.WindowState = WindowState.Maximized }
},
Bindings = Bindings =
{ {
{ {
@ -241,10 +265,7 @@ namespace CPF.Toolkit.Controls
} }
} }
}, },
Commands = Commands = { { nameof(Button.Click),(s,e) => this.WindowState = WindowState.Normal } },
{
{ nameof(Button.Click),(s,e) => this.WindowState = WindowState.Normal }
},
Bindings = Bindings =
{ {
{ {
@ -252,7 +273,7 @@ namespace CPF.Toolkit.Controls
nameof(Window.WindowState), nameof(Window.WindowState),
this, this,
BindingMode.OneWay, BindingMode.OneWay,
a => (WindowState)a == WindowState.Normal ? Visibility.Collapsed : Visibility.Visible a => ((WindowState)a).Or( WindowState.Normal, WindowState.Minimized) ? Visibility.Collapsed : Visibility.Visible
} }
} }
} }
@ -287,6 +308,16 @@ namespace CPF.Toolkit.Controls
} }
} }
}, },
Bindings=
{
{
nameof(Visibility),
nameof(this.CloseBox),
this,
BindingMode.OneWay,
a=>(bool)a?Visibility.Visible: Visibility.Collapsed
}
},
} }
} }
}, },
@ -298,12 +329,14 @@ namespace CPF.Toolkit.Controls
nameof(Thumb.DragDelta), nameof(Thumb.DragDelta),
(s,e) => (s,e) =>
{ {
if (this.WindowState == WindowState.Maximized) return; if (this.WindowState.Or(WindowState.Normal, WindowState.Minimized))
{
var arge = e as DragDeltaEventArgs; var arge = e as DragDeltaEventArgs;
this.MarginLeft += arge.HorizontalChange; this.MarginLeft += arge.HorizontalChange;
this.MarginTop += arge.VerticalChange; this.MarginTop += arge.VerticalChange;
this.normalPos = new Point(this.MarginLeft.Value, this.MarginTop.Value); this.normalPos = new Point(this.MarginLeft.Value, this.MarginTop.Value);
} }
}
}, },
{ {
nameof(DoubleClick), nameof(DoubleClick),
@ -328,7 +361,27 @@ namespace CPF.Toolkit.Controls
Child = this.Content, Child = this.Content,
}, },
} }
},
},
Bindings =
{
{
nameof(Border.ShadowBlur),
nameof(IWindow.WindowState),
this,
BindingMode.OneWay,
a => (WindowState)a == WindowState.Maximized||(WindowState)a == WindowState.FullScreen ? 0 : ShadowBlur
},
{
nameof(Border.ShadowBlur),
nameof(ShadowBlur),
this,
BindingMode.OneWay,
a => this.WindowState == WindowState.Maximized||this. WindowState == WindowState.FullScreen ? 0 : (byte)a
},
}
}); });
this.Content.Margin = "0"; this.Content.Margin = "0";
this.Content.ClipToBounds = true; this.Content.ClipToBounds = true;
} }
@ -347,14 +400,15 @@ 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.Height = this.MinHeight;
break; break;
case WindowState.Maximized: case WindowState.Maximized:
case WindowState.FullScreen:
this.Size = SizeField.Fill; this.Size = SizeField.Fill;
this.MarginLeft = 0; this.MarginLeft = 0;
this.MarginTop = 0; this.MarginTop = 0;
break; break;
case WindowState.FullScreen:
break;
} }
} }
break; break;
@ -363,9 +417,19 @@ namespace CPF.Toolkit.Controls
case nameof(Width): case nameof(Width):
case nameof(Height): case nameof(Height):
case nameof(ActualSize): case nameof(ActualSize):
if (this.WindowState == WindowState.Normal) switch (this.WindowState)
{ {
case WindowState.Normal:
this.normalSize = this.Size; this.normalSize = this.Size;
break;
case WindowState.Minimized:
this.Width = this.MinWidth;
this.Height = this.MinHeight;
break;
case WindowState.Maximized:
break;
case WindowState.FullScreen:
break;
} }
break; break;