This commit is contained in:
Sakura 2023-11-24 22:58:59 +08:00
parent 235e8ec59e
commit b79e63da71
3 changed files with 46 additions and 85 deletions

View File

@ -25,24 +25,32 @@ 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 // new MdiWindow
{ // {
Title = "test", // Title = "test",
Content = new WrapPanel // Content = new WrapPanel
{ // {
Children = // 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 },
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}",
Content = new WrapPanel
{
} }
})); .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";

View File

@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Text; using System.Text;
namespace CPF.Toolkit.Controls namespace CPF.Toolkit.Controls
@ -38,7 +39,14 @@ namespace CPF.Toolkit.Controls
protected override void OnUIElementAdded(UIElementAddedEventArgs e) protected override void OnUIElementAdded(UIElementAddedEventArgs e)
{ {
e.Element.PreviewMouseDown += Element_PreviewMouseDown; ;
base.OnUIElementAdded(e); base.OnUIElementAdded(e);
} }
private void Element_PreviewMouseDown(object sender, Input.MouseButtonEventArgs e)
{
var view = sender as UIElement;
view.ZIndex = this.Children.Max(x => x.ZIndex) + 1;
}
} }
} }

View File

@ -37,6 +37,7 @@ namespace CPF.Toolkit.Controls
protected override void InitializeComponent() protected override void InitializeComponent()
{ {
var bar = (ViewFill)"154,180,208"; var bar = (ViewFill)"154,180,208";
var thubmEnabled = new BindingDescribe(this, nameof(WindowState), BindingMode.OneWay, b => ((WindowState)b) == WindowState.Normal);
this.Size = normalSize; this.Size = normalSize;
this.Background = null; this.Background = null;
this.MarginLeft = 0; this.MarginLeft = 0;
@ -81,6 +82,7 @@ namespace CPF.Toolkit.Controls
Background = bar, Background = bar,
Cursor = Cursors.SizeNorthSouth, Cursor = Cursors.SizeNorthSouth,
Attacheds = { { Grid.ColumnSpan,3 } }, Attacheds = { { Grid.ColumnSpan,3 } },
[nameof(IsEnabled)] = thubmEnabled,
Commands = Commands =
{ {
{ {
@ -94,7 +96,7 @@ namespace CPF.Toolkit.Controls
} }
} }
} }
} },
}, },
new Thumb new Thumb
{ {
@ -104,6 +106,7 @@ namespace CPF.Toolkit.Controls
Cursor = Cursors.SizeWestEast, Cursor = Cursors.SizeWestEast,
IsEnabled = false, IsEnabled = false,
Attacheds = { { Grid.ColumnIndex,0 } ,{ Grid.RowSpan,4 } }, Attacheds = { { Grid.ColumnIndex,0 } ,{ Grid.RowSpan,4 } },
[nameof(IsEnabled)] = thubmEnabled,
Commands = Commands =
{ {
{ {
@ -127,6 +130,7 @@ namespace CPF.Toolkit.Controls
Cursor = Cursors.SizeWestEast, Cursor = Cursors.SizeWestEast,
MarginRight = 0, MarginRight = 0,
Attacheds = { { Grid.ColumnIndex,2 },{ Grid.RowSpan,4 } }, Attacheds = { { Grid.ColumnIndex,2 },{ Grid.RowSpan,4 } },
[nameof(IsEnabled)] = thubmEnabled,
Commands = { { nameof(Thumb.DragDelta),(s,e) => this.Width += (e as DragDeltaEventArgs).HorizontalChange } } Commands = { { nameof(Thumb.DragDelta),(s,e) => this.Width += (e as DragDeltaEventArgs).HorizontalChange } }
}, },
new Thumb new Thumb
@ -136,6 +140,7 @@ namespace CPF.Toolkit.Controls
Background = bar, Background = bar,
Cursor = Cursors.SizeNorthSouth, Cursor = Cursors.SizeNorthSouth,
Attacheds = { { Grid.RowIndex,3 },{ Grid.ColumnSpan,3 } }, Attacheds = { { Grid.RowIndex,3 },{ Grid.ColumnSpan,3 } },
[nameof(IsEnabled)] = thubmEnabled,
Commands = { { nameof(Thumb.DragDelta),(s,e) => this.Height += (e as DragDeltaEventArgs).VerticalChange } } Commands = { { nameof(Thumb.DragDelta),(s,e) => this.Height += (e as DragDeltaEventArgs).VerticalChange } }
}, },
new Thumb new Thumb
@ -183,31 +188,13 @@ namespace CPF.Toolkit.Controls
IsAntiAlias = true, IsAntiAlias = true,
StrokeFill = "black" StrokeFill = "black"
}, },
Bindings= [nameof(Visibility)] = new BindingDescribe(this,nameof(MinimizeBox),BindingMode.OneWay,a=>(bool)a?Visibility.Visible: Visibility.Collapsed),
{
{
nameof(Visibility),
nameof(MinimizeBox),
this,
BindingMode.OneWay,
a=>(bool)a?Visibility.Visible: Visibility.Collapsed
}
},
Commands = { { nameof(Button.Click),(s,e) => this.WindowState = WindowState.Minimized } }, Commands = { { nameof(Button.Click),(s,e) => this.WindowState = WindowState.Minimized } },
}, },
new Panel new Panel
{ {
Height = "100%", Height = "100%",
Bindings = [nameof(Visibility)] = new BindingDescribe(this,nameof(MaximizeBox),BindingMode.OneWay,a => (bool)a ? Visibility.Visible : Visibility.Collapsed),
{
{
nameof(Visibility),
nameof(MaximizeBox),
this,
BindingMode.OneWay,
a => (bool)a ? Visibility.Visible : Visibility.Collapsed
}
},
Children = Children =
{ {
new SystemButton new SystemButton
@ -221,16 +208,7 @@ 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 } },
Bindings = [nameof(Visibility)] = new BindingDescribe(this,nameof(WindowState),BindingMode.OneWay,a => ((WindowState)a).Or(WindowState.Maximized,WindowState.FullScreen) ? Visibility.Collapsed : Visibility.Visible),
{
{
nameof(Border.Visibility),
nameof(this.WindowState),
this,
BindingMode.OneWay,
a => (WindowState)a == WindowState.Maximized || (WindowState)a == WindowState.FullScreen ? Visibility.Collapsed : Visibility.Visible
}
}
}, },
new SystemButton new SystemButton
{ {
@ -266,16 +244,7 @@ namespace CPF.Toolkit.Controls
} }
}, },
Commands = { { nameof(Button.Click),(s,e) => this.WindowState = WindowState.Normal } }, Commands = { { nameof(Button.Click),(s,e) => this.WindowState = WindowState.Normal } },
Bindings = [nameof(Visibility)] = new BindingDescribe(this,nameof(WindowState),BindingMode.OneWay,a => ((WindowState)a).Or( WindowState.Normal, WindowState.Minimized) ? Visibility.Collapsed : Visibility.Visible)
{
{
nameof(Border.Visibility),
nameof(Window.WindowState),
this,
BindingMode.OneWay,
a => ((WindowState)a).Or( WindowState.Normal, WindowState.Minimized) ? Visibility.Collapsed : Visibility.Visible
}
}
} }
} }
}, },
@ -308,16 +277,7 @@ namespace CPF.Toolkit.Controls
} }
} }
}, },
Bindings= [nameof(Visibility)] = new BindingDescribe(this,nameof(this.CloseBox),BindingMode.OneWay,a=>(bool)a?Visibility.Visible: Visibility.Collapsed)
{
{
nameof(Visibility),
nameof(this.CloseBox),
this,
BindingMode.OneWay,
a=>(bool)a?Visibility.Visible: Visibility.Collapsed
}
},
} }
} }
}, },
@ -363,23 +323,8 @@ namespace CPF.Toolkit.Controls
} }
}, },
}, },
Bindings = [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(ShadowBlur), BindingMode.OneWay, a => ((WindowState)a).Or(WindowState.Maximized, WindowState.FullScreen) ? 0 : (byte)a),
{
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";