From 9a77cf208662a11f01b8de58a2c162a6abb86f1c Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Tue, 12 Mar 2019 00:47:25 +0800 Subject: [PATCH] add Dialog --- HandyControl/Controls/Other/Dialog.cs | 62 +++++++++++++++++- HandyControl/Controls/Other/GotoTop.cs | 2 +- .../Interactivity/AdornerContainer.cs | 3 +- .../Themes/Styles/Base/DialogBaseStyle.xaml | 12 +++- HandyControl/Tools/Helper/VisualHelper.cs | 8 +-- HandyControlDemo/App.xaml | 2 +- HandyControlDemo/HandyControlDemo.csproj | 8 +++ .../Properties/Langs/Lang.Designer.cs | 18 +++++ .../Properties/Langs/Lang.en.resx | 6 ++ HandyControlDemo/Properties/Langs/Lang.resx | 6 ++ .../UserControl/Basic/TextDialog.xaml | 15 +++++ .../UserControl/Basic/TextDialog.xaml.cs | 10 +++ .../UserControl/Controls/DialogDemoCtl.xaml | 6 +- .../ViewModel/Controls/DialogDemoViewModel.cs | 19 ++++++ .../ViewModel/ViewModelLocator.cs | 3 + README.md | 8 ++- Resources/Dialog.png | Bin 0 -> 29998 bytes 17 files changed, 174 insertions(+), 14 deletions(-) create mode 100644 HandyControlDemo/UserControl/Basic/TextDialog.xaml create mode 100644 HandyControlDemo/UserControl/Basic/TextDialog.xaml.cs create mode 100644 HandyControlDemo/ViewModel/Controls/DialogDemoViewModel.cs create mode 100644 Resources/Dialog.png diff --git a/HandyControl/Controls/Other/Dialog.cs b/HandyControl/Controls/Other/Dialog.cs index 1b6f1bc0..a5f18d03 100644 --- a/HandyControl/Controls/Other/Dialog.cs +++ b/HandyControl/Controls/Other/Dialog.cs @@ -1,9 +1,69 @@ using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using HandyControl.Interactivity; +using HandyControl.Tools; namespace HandyControl.Controls { public class Dialog : ContentControl { - + private Adorner _container; + + public Dialog() + { + CommandBindings.Add(new CommandBinding(ControlCommands.Close, (s, e) => Close())); + } + + public static Dialog Show(object content) + { + var dialog = new Dialog + { + Content = content + }; + + var window = VisualHelper.GetActiveWindow(); + if (window != null) + { + var decorator = VisualHelper.GetChild(window); + if (decorator != null) + { + if (decorator.Child != null) + { + decorator.Child.IsEnabled = false; + } + var layer = decorator.AdornerLayer; + if (layer != null) + { + var container = new AdornerContainer(layer) + { + Child = dialog + }; + dialog._container = container; + layer.Add(container); + } + } + } + + return dialog; + } + + public void Close() + { + var window = VisualHelper.GetActiveWindow(); + if (window != null) + { + var decorator = VisualHelper.GetChild(window); + if (decorator != null) + { + if (decorator.Child != null) + { + decorator.Child.IsEnabled = true; + } + var layer = decorator.AdornerLayer; + layer?.Remove(_container); + } + } + } } } \ No newline at end of file diff --git a/HandyControl/Controls/Other/GotoTop.cs b/HandyControl/Controls/Other/GotoTop.cs index 62d004a3..63df976c 100644 --- a/HandyControl/Controls/Other/GotoTop.cs +++ b/HandyControl/Controls/Other/GotoTop.cs @@ -30,7 +30,7 @@ namespace HandyControl.Controls { _scrollViewer.ScrollChanged -= ScrollViewer_ScrollChanged; } - _scrollViewer = VisualHelper.GetGetChild(obj); + _scrollViewer = VisualHelper.GetChild(obj); if (_scrollViewer != null) { _scrollViewer.ScrollChanged += ScrollViewer_ScrollChanged; diff --git a/HandyControl/Interactivity/AdornerContainer.cs b/HandyControl/Interactivity/AdornerContainer.cs index 4ffc4f93..4fea569d 100644 --- a/HandyControl/Interactivity/AdornerContainer.cs +++ b/HandyControl/Interactivity/AdornerContainer.cs @@ -14,8 +14,7 @@ namespace HandyControl.Interactivity public UIElement Child { - get => - _child; + get => _child; set { AddVisualChild(value); diff --git a/HandyControl/Themes/Styles/Base/DialogBaseStyle.xaml b/HandyControl/Themes/Styles/Base/DialogBaseStyle.xaml index 4516fd43..dc3c8493 100644 --- a/HandyControl/Themes/Styles/Base/DialogBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/DialogBaseStyle.xaml @@ -3,7 +3,17 @@ xmlns:controls="clr-namespace:HandyControl.Controls"> \ No newline at end of file diff --git a/HandyControl/Tools/Helper/VisualHelper.cs b/HandyControl/Tools/Helper/VisualHelper.cs index 77b127a8..5ba5ae07 100644 --- a/HandyControl/Tools/Helper/VisualHelper.cs +++ b/HandyControl/Tools/Helper/VisualHelper.cs @@ -27,18 +27,18 @@ namespace HandyControl.Tools : null; } - internal static T GetGetChild(DependencyObject d) where T : DependencyObject + internal static T GetChild(DependencyObject d) where T : DependencyObject { - if (d is T scrollViewer) + if (d is T t) { - return scrollViewer; + return t; } for (int i = 0; i < VisualTreeHelper.GetChildrenCount(d); i++) { var child = VisualTreeHelper.GetChild(d, i); - var result = GetGetChild(child); + var result = GetChild(child); if (result != null) return result; } diff --git a/HandyControlDemo/App.xaml b/HandyControlDemo/App.xaml index dea6f894..cdd77978 100644 --- a/HandyControlDemo/App.xaml +++ b/HandyControlDemo/App.xaml @@ -31,7 +31,7 @@ - + diff --git a/HandyControlDemo/HandyControlDemo.csproj b/HandyControlDemo/HandyControlDemo.csproj index c9039d90..3c727753 100644 --- a/HandyControlDemo/HandyControlDemo.csproj +++ b/HandyControlDemo/HandyControlDemo.csproj @@ -130,6 +130,9 @@ ChatBox.xaml + + TextDialog.xaml + AnimationPathDemoCtl.xaml @@ -355,6 +358,7 @@ + @@ -443,6 +447,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/HandyControlDemo/Properties/Langs/Lang.Designer.cs b/HandyControlDemo/Properties/Langs/Lang.Designer.cs index 33c85990..0ed9c7fa 100644 --- a/HandyControlDemo/Properties/Langs/Lang.Designer.cs +++ b/HandyControlDemo/Properties/Langs/Lang.Designer.cs @@ -798,6 +798,15 @@ namespace HandyControlDemo.Properties.Langs { } } + /// + /// 查找类似 请稍后... 的本地化字符串。 + /// + public static string PleaseWait { + get { + return ResourceManager.GetString("PleaseWait", resourceCulture); + } + } + /// /// 查找类似 请输入内容 的本地化字符串。 /// @@ -1113,6 +1122,15 @@ namespace HandyControlDemo.Properties.Langs { } } + /// + /// 查找类似 文本对话框 的本地化字符串。 + /// + public static string TextDialog { + get { + return ResourceManager.GetString("TextDialog", resourceCulture); + } + } + /// /// 查找类似 时间条 的本地化字符串。 /// diff --git a/HandyControlDemo/Properties/Langs/Lang.en.resx b/HandyControlDemo/Properties/Langs/Lang.en.resx index 5147ebc0..5a368f22 100644 --- a/HandyControlDemo/Properties/Langs/Lang.en.resx +++ b/HandyControlDemo/Properties/Langs/Lang.en.resx @@ -516,4 +516,10 @@ Dialog + + TextDialog + + + Please wait... + \ No newline at end of file diff --git a/HandyControlDemo/Properties/Langs/Lang.resx b/HandyControlDemo/Properties/Langs/Lang.resx index b3d34753..05c82167 100644 --- a/HandyControlDemo/Properties/Langs/Lang.resx +++ b/HandyControlDemo/Properties/Langs/Lang.resx @@ -516,4 +516,10 @@ 对话框 + + 文本对话框 + + + 请稍后... + \ No newline at end of file diff --git a/HandyControlDemo/UserControl/Basic/TextDialog.xaml b/HandyControlDemo/UserControl/Basic/TextDialog.xaml new file mode 100644 index 00000000..eb470cc8 --- /dev/null +++ b/HandyControlDemo/UserControl/Basic/TextDialog.xaml @@ -0,0 +1,15 @@ + + + +