diff --git a/CPF.Toolkit.Demo/MainView.cs b/CPF.Toolkit.Demo/MainView.cs index e44c0aa..ea82b52 100644 --- a/CPF.Toolkit.Demo/MainView.cs +++ b/CPF.Toolkit.Demo/MainView.cs @@ -28,7 +28,6 @@ namespace CPF.Toolkit.Demo Background = null; var vm = new MainViewModel(); this.DataContext = this.CommandContext = vm; - vm.Dialog = new DialogService(this); Children.Add(new WindowFrame(this, new WrapPanel { @@ -61,8 +60,13 @@ namespace CPF.Toolkit.Demo Content = "Warn", Commands = { { nameof(Button.Click),(s,e) => vm.Dialog.Warn("这是一条测试消息") } } }, + new Button + { + Content = "关闭窗体", + Commands = { { nameof(Button.Click),(s,e) => vm.Test() } } + }, } - })) ; + })); } } } diff --git a/CPF.Toolkit.Demo/MainViewModel.cs b/CPF.Toolkit.Demo/MainViewModel.cs index 26342a4..0aa3915 100644 --- a/CPF.Toolkit.Demo/MainViewModel.cs +++ b/CPF.Toolkit.Demo/MainViewModel.cs @@ -1,4 +1,5 @@ -using System; +using CPF.Controls; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,7 +9,20 @@ namespace CPF.Toolkit.Demo { internal class MainViewModel : ViewModelBase { + bool isClose = false; + public void Test() + { + if (this.Dialog.Ask("确定要关闭吗") == "确定") + { + this.isClose = true; + this.Close(); + } + } - + protected override void OnClose(ClosingEventArgs e) + { + e.Cancel = !this.isClose; + base.OnClose(e); + } } } diff --git a/CPF.Toolkit.Demo/Program.cs b/CPF.Toolkit.Demo/Program.cs index c0fb9fa..6ae9276 100644 --- a/CPF.Toolkit.Demo/Program.cs +++ b/CPF.Toolkit.Demo/Program.cs @@ -1,5 +1,7 @@ -using CPF.Platform; +using CPF.Controls; +using CPF.Platform; using CPF.Skia; +using CPF.Toolkit.Dialogs; using CPF.Windows; namespace CPF.Toolkit.Demo @@ -14,7 +16,8 @@ namespace CPF.Toolkit.Demo , (OperatingSystemType.OSX, new CPF.Mac.MacPlatform(), new SkiaDrawingFactory { UseGPU = false }) , (OperatingSystemType.Linux, new CPF.Linux.LinuxPlatform(), new SkiaDrawingFactory { UseGPU = false }) ); - Application.Run(new MainView { }); + + Application.Run(ViewManager.View()); } } } diff --git a/CPF.Toolkit/Dialogs/DialogFrame.cs b/CPF.Toolkit/Dialogs/DialogFrame.cs index 9b8d908..2a5ff7f 100644 --- a/CPF.Toolkit/Dialogs/DialogFrame.cs +++ b/CPF.Toolkit/Dialogs/DialogFrame.cs @@ -16,17 +16,6 @@ namespace CPF.Toolkit.Dialogs this.window = window; this.content = content; } - - /// - /// 是否显示最大化还原按钮 - /// - public bool MaximizeBox { get { return GetValue(); } set { SetValue(value); } } - /// - /// 是否显示最小化 - /// - [PropertyMetadata(true)] - public bool MinimizeBox { get { return GetValue(); } set { SetValue(value); } } - IWindow window; /// /// 关联的窗体 @@ -47,15 +36,6 @@ namespace CPF.Toolkit.Dialogs get { return content; } } - IEnumerable systemButtons; - /// - /// 系统按钮集合 - /// - [NotCpfProperty] - public IEnumerable SystemButtons - { - get { return systemButtons; } - } /// /// 阴影宽度 @@ -79,7 +59,6 @@ namespace CPF.Toolkit.Dialogs protected override void InitializeComponent() { - ViewFill color = "black"; ViewFill hoverColor = "255,255,255,40"; Width = "100%"; @@ -155,10 +134,6 @@ namespace CPF.Toolkit.Dialogs nameof(MouseDown), nameof(IWindow.DragMove), Window - }, - { - nameof(DoubleClick), - (s,e)=> DoubleClickTitle() } }, Children = @@ -292,19 +267,5 @@ namespace CPF.Toolkit.Dialogs grid.Children.Add(Content, 0, 1); } } - - protected void DoubleClickTitle() - { - if (MaximizeBox) - { - this.Delay(TimeSpan.FromMilliseconds(100), () => - { - if (Window.WindowState == WindowState.Normal) - { Window.WindowState = WindowState.Maximized; } - else if (Window.WindowState == WindowState.Maximized) - { Window.WindowState = WindowState.Normal; } - }); - } - } } } diff --git a/CPF.Toolkit/Dialogs/DialogView.cs b/CPF.Toolkit/Dialogs/DialogView.cs index 1a5d476..d1a76ee 100644 --- a/CPF.Toolkit/Dialogs/DialogView.cs +++ b/CPF.Toolkit/Dialogs/DialogView.cs @@ -3,6 +3,7 @@ using CPF.Animation; using CPF.Charts; using CPF.Controls; using CPF.Drawing; +using CPF.Input; using CPF.Shapes; using CPF.Styling; using CPF.Svg; @@ -126,11 +127,7 @@ namespace CPF.Toolkit.Dialogs }).ToList().ForEach(c => { p.Children.Add(c); - c.Click += C_Click; - if (c.Content.ToString() == this.DefaultButton) - { - c.Focus(); - } + c.Click += Button_Click; }); textBox.TextChanged += TextBox_TextChanged; } @@ -150,9 +147,22 @@ namespace CPF.Toolkit.Dialogs } } - private void C_Click(object sender, RoutedEventArgs e) + private void Button_Click(object sender, RoutedEventArgs e) { this.DialogResult = (sender as Button).Content; + this.Close(); + } + + protected override void OnKeyUp(KeyEventArgs e) + { + if (e.Key.Or(Keys.Enter, Keys.Space)) + { + var buttons = this.Find