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/HandyControl.csproj b/HandyControl/HandyControl.csproj index a01d6620..a5a8e24d 100644 --- a/HandyControl/HandyControl.csproj +++ b/HandyControl/HandyControl.csproj @@ -398,6 +398,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -450,6 +454,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile 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 new file mode 100644 index 00000000..dc3c8493 --- /dev/null +++ b/HandyControl/Themes/Styles/Base/DialogBaseStyle.xaml @@ -0,0 +1,19 @@ + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Dialog.xaml b/HandyControl/Themes/Styles/Dialog.xaml new file mode 100644 index 00000000..d74f807e --- /dev/null +++ b/HandyControl/Themes/Styles/Dialog.xaml @@ -0,0 +1,10 @@ + + + + + + +