CPF/CPF.Toolkit.Demo/TestMdiView.cs

140 lines
4.5 KiB
C#
Raw Normal View History

2023-11-23 23:46:40 +08:00
using CPF;
using CPF.Animation;
using CPF.Charts;
using CPF.Controls;
using CPF.Drawing;
using CPF.Shapes;
using CPF.Styling;
using CPF.Svg;
using CPF.Toolkit.Controls;
2023-11-29 17:07:17 +08:00
using CPF.Toolkit.Dialogs;
2023-11-23 23:46:40 +08:00
using System;
using System.Collections.Generic;
2023-11-29 17:07:17 +08:00
using System.Diagnostics;
2023-11-23 23:46:40 +08:00
using System.Linq;
using System.Text;
namespace CPF.Toolkit.Demo
{
public class TestMdiView : Window
{
protected override void InitializeComponent()
{
this.CanResize = true;
this.Title = "标题";
this.Width = 1280;
this.Height = 720;
this.Background = null;
2023-11-29 17:07:17 +08:00
var frame = this.Children.Add(new WindowFrame(this, new Grid
2023-11-23 23:46:40 +08:00
{
2023-11-29 17:07:17 +08:00
Size = SizeField.Fill,
RowDefinitions =
{
new RowDefinition{ Height = 30 },
new RowDefinition{ },
},
2023-11-28 17:31:16 +08:00
Children =
{
2023-11-29 17:07:17 +08:00
new MdiHost
{
Size = SizeField.Fill,
2023-11-30 16:33:03 +08:00
Attacheds = { { Grid.RowIndex,1 } },
TaskBarPlacement = TaskBarPlacement.Top,
2023-11-29 17:07:17 +08:00
}.Assign(out var host),
new WrapPanel
{
Orientation = Orientation.Horizontal,
Size = SizeField.Fill,
Children =
{
new Button
{
Height = "100%",
Content = "New Window",
[nameof(Button.Click)] = new CommandDescribe((s,e) => host.Children.Add(new M{ Title = $"Title{host.Children.Count}", })),
},
new Button
{
Height = "100%",
Content = "任务栏居上",
[nameof(Button.Click)] = new CommandDescribe((s,e) => host.TaskBarPlacement = TaskBarPlacement.Top),
},
new Button
{
Height = "100%",
Content = "任务栏居下",
[nameof(Button.Click)] = new CommandDescribe((s,e) => host.TaskBarPlacement = TaskBarPlacement.Bottom),
},
},
},
2023-11-28 17:31:16 +08:00
},
}));
2023-11-29 17:07:17 +08:00
//frame.CaptionBackgrund = "white";
//frame.CaptionForeground = "black";
//frame.ControlBoxStroke = "black";
2023-11-24 14:26:26 +08:00
frame.MaximizeBox = true;
2023-11-23 23:46:40 +08:00
}
}
2023-11-29 17:07:17 +08:00
internal class M : MdiWindow
{
protected override void InitializeComponent()
{
var vm = new MV { Dialog = new DialogService(this.Root as Window) };
this.DataContext = vm;
this.CommandContext = vm;
this.Content = new WrapPanel
{
Size = SizeField.Fill,
Children =
{
new Button
{
Content = "close",
[nameof(Button.Click)] = new CommandDescribe((s,e) => vm.TestClose())
},
new Button
{
Content = "loading",
[nameof(Button.AsyncClick)] = new CommandDescribe(async (s,e) => await vm.LoadingTest()),
},
new Button
{
Content = "alert",
[nameof(Button.Click)] = new CommandDescribe( (s,e) => vm.TestAlert()),
},
},
};
}
}
internal class MV : ViewModelBase
{
public void TestClose()
{
this.Close();
}
public void TestAlert()
{
this.Dialog.Warn("test");
}
public async Task LoadingTest()
{
var result = await this.ShowLoading(async () =>
{
await Task.Delay(3000);
return "ok";
});
Debug.WriteLine(result);
}
protected override void OnClose(ClosingEventArgs e)
{
e.Cancel = this.Dialog.Ask("确定要关闭吗") != "确定";
base.OnClose(e);
}
}
2023-11-23 23:46:40 +08:00
}