diff --git a/CPF.Toolkit.Demo/MainView.cs b/CPF.Toolkit.Demo/MainView.cs
index 0b942e6..e186886 100644
--- a/CPF.Toolkit.Demo/MainView.cs
+++ b/CPF.Toolkit.Demo/MainView.cs
@@ -18,7 +18,6 @@ namespace CPF.Toolkit.Demo
protected override void InitializeComponent()
{
//LoadStyleFile("res://CPF.Toolkit.Demo/Stylesheet1.css");
- this.Behaviors.Add(new ViewBehavior());
this.Title = "标题";
this.Width = 500;
@@ -39,6 +38,7 @@ namespace CPF.Toolkit.Demo
}
},
}));
+ this.Behaviors.Add(new ViewBehavior());
}
}
}
diff --git a/CPF.Toolkit.Demo/MainViewModel.cs b/CPF.Toolkit.Demo/MainViewModel.cs
index 8bf3f2e..8fc4d55 100644
--- a/CPF.Toolkit.Demo/MainViewModel.cs
+++ b/CPF.Toolkit.Demo/MainViewModel.cs
@@ -15,7 +15,7 @@ namespace CPF.Toolkit.Demo
public void Test()
{
- this.Close();
+ this.Dialog.Alert("确定删除所选的文件吗?", "确定删除", DialogType.Warn, "", "取消", "删除");
}
//protected override void OnClosing(ClosingEventArgs e)
diff --git a/CPF.Toolkit/CPF.Toolkit.csproj b/CPF.Toolkit/CPF.Toolkit.csproj
index 4eaec2d..a49aac9 100644
--- a/CPF.Toolkit/CPF.Toolkit.csproj
+++ b/CPF.Toolkit/CPF.Toolkit.csproj
@@ -5,7 +5,17 @@
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CPF.Toolkit/DialogService.cs b/CPF.Toolkit/DialogService.cs
new file mode 100644
index 0000000..1c1aeba
--- /dev/null
+++ b/CPF.Toolkit/DialogService.cs
@@ -0,0 +1,63 @@
+using CPF.Controls;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace CPF.Toolkit
+{
+ public interface IDialog
+ {
+ IDialogService Dialog { get; set; }
+ }
+
+ public interface IDialogService
+ {
+ string Alert(string text, string title, DialogType dialogType, string defaultButton, params string[] buttons);
+ void Alert(string text);
+ void Sucess(string text);
+ void Error(string text);
+ void Warn(string text);
+ bool Ask(string text);
+ }
+
+ public class DialogService : IDialogService
+ {
+ public DialogService(Window owner)
+ {
+ this.owner = owner ?? throw new ArgumentNullException(nameof(owner));
+ }
+ Window owner;
+
+ public string Alert(string text, string title, DialogType dialogType, string defaultButton, params string[] buttons)
+ {
+ var view = new DialogView(text, title, dialogType, defaultButton, buttons);
+ var result = view.ShowDialogSync(owner);
+ return result?.ToString();
+ }
+
+ public void Alert(string text)
+ {
+ this.Alert(text, "消息", DialogType.None, "确定", "确定");
+ }
+
+ public bool Ask(string text)
+ {
+ return this.Alert(text, "询问", DialogType.Ask, "确定", "确定", "取消") == "确定";
+ }
+
+ public void Error(string text)
+ {
+ this.Alert(text, "错误", DialogType.Error, defaultButton: "确定", "确定");
+ }
+
+ public void Sucess(string text)
+ {
+ this.Alert(text, "成功", DialogType.Sucess, "确定", "确定");
+ }
+
+ public void Warn(string text)
+ {
+ this.Alert(text, "警告", DialogType.Warn, "确定", "确定");
+ }
+ }
+}
diff --git a/CPF.Toolkit/DialogView.cs b/CPF.Toolkit/DialogView.cs
new file mode 100644
index 0000000..51ea3cb
--- /dev/null
+++ b/CPF.Toolkit/DialogView.cs
@@ -0,0 +1,163 @@
+using CPF.Controls;
+using CPF.Drawing;
+using CPF.Input;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace CPF.Toolkit
+{
+ internal class DialogView : Window
+ {
+ public DialogView(string text, string title, DialogType dialogType, string defaultButton, params string[] buttons)
+ {
+ this.Title = title;
+ this.Text = text;
+ this.Buttons = buttons;
+ this.DefaultButton = defaultButton;
+ this.DialogType = dialogType;
+ }
+
+ public DialogType DialogType { get => GetValue(); set => SetValue(value); }
+ public string DefaultButton { get => GetValue(); set => SetValue(value); }
+ public string Text { get => GetValue(); set => SetValue(value); }
+ public string[] Buttons { get => GetValue(); set => SetValue(value); }
+
+ protected override void InitializeComponent()
+ {
+ this.ShowInTaskbar = false;
+ this.MaxWidth = 800;
+ this.MinWidth = 400;
+ this.MaxHeight = 600;
+ this.MinHeight = 250;
+ this.CanResize = false;
+ this.Width = "auto";
+ this.Height = "auto";
+ this.Background = null;
+ var frame = this.Children.Add(new WindowFrame(this, new Grid
+ {
+ Size = SizeField.Fill,
+ //LineFill = "red",
+ //LineStroke = new Stroke(1),
+ RowDefinitions =
+ {
+ new RowDefinition{ Height = "auto" },
+ new RowDefinition{ },
+ new RowDefinition{ Height = 35 },
+ },
+ Children =
+ {
+ new Picture
+ {
+ Stretch = Stretch.None,
+ Height = "70",
+ Bindings =
+ {
+ {
+ nameof(Visibility),
+ nameof(DialogType),
+ this,BindingMode.OneWay,
+ (DialogType t) => t == DialogType.None ? Visibility.Collapsed : Visibility.Visible
+ },
+ {
+ nameof(Picture.Source),
+ nameof(DialogType),
+ this,BindingMode.OneWay,
+ (DialogType t) =>
+ {
+ switch (t)
+ {
+ case DialogType.Sucess: return "res://CPF.Toolkit/Images/sucess.png";
+ case DialogType.Error:return"res://CPF.Toolkit/Images/error.png";
+ case DialogType.Ask: return"res://CPF.Toolkit/Images/ask.png";
+ case DialogType.Warn:return "res://CPF.Toolkit/Images/warn.png";
+ default:return null;
+ }
+ }
+ }
+ }
+ },
+ new TextBox
+ {
+ Attacheds = { { Grid.RowIndex,1 } },
+ BorderType = BorderType.BorderThickness,
+ BorderStroke = new Stroke(1, DashStyles.Solid),
+ BorderThickness = new Thickness(0,0,0,1),
+ //BorderFill = "Silver",
+ IsReadOnly = true,
+ Size = SizeField.Fill,
+ FontSize = 16,
+ WordWarp = true,
+ TextAlignment = TextAlignment.Center,
+ MarginTop = 30,
+ Bindings =
+ {
+ { nameof(TextBox.Text),nameof(Text),this,BindingMode.OneWay}
+ }
+ }.Assign(out var textBox),
+ new StackPanel
+ {
+ Height = "100%",
+ Attacheds = { { Grid.RowIndex,2 } },
+ MarginBottom = 4,
+ Orientation = Orientation.Horizontal,
+ }
+ .LoopCreate(this.Buttons.Length, i => new Button
+ {
+ Content = this.Buttons[i],
+ MinWidth = this.Buttons.Length <= 1 ? 80 : 65,
+ Background = "white",
+ BorderFill = "236,236,236",
+ Height = "95%",
+ MarginRight = 5,
+ Commands = { { nameof(Button.Click),(s,e) => this.DialogResult = this.Buttons[i] } }
+ }),
+ }
+ }));
+ var controlBox = frame.Find().FirstOrDefault(x => x.Name == "controlBox");
+ var caption = frame.Find().FirstOrDefault(x => x.Name == "caption");
+ var title = frame.Find().FirstOrDefault(x => x.Name == "title");
+ controlBox.Visibility = Visibility.Collapsed;
+ caption.Background = "white";
+ title.Foreground = "black";
+ textBox.TextChanged += TextBox_TextChanged;
+ }
+
+ private void TextBox_TextChanged(object sender, EventArgs e)
+ {
+ var textBox = sender as TextBox;
+ if (textBox.Document.Lines.Count > 5)
+ {
+ textBox.TextAlignment = TextAlignment.Left;
+ textBox.Height = "100%";
+ }
+ else
+ {
+ textBox.TextAlignment = TextAlignment.Center;
+ textBox.Height = "auto";
+ }
+ }
+
+ protected override void OnKeyUp(KeyEventArgs e)
+ {
+ if (e.Key == Keys.Enter || e.Key == Keys.Space)
+ {
+ var buttons = this.Find