add Dialog
This commit is contained in:
1 parent
e6719725df
commit
9a77cf2086
17 files changed
+174
-14
No files matched your search
@@ -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<AdornerDecorator>(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<AdornerDecorator>(window);
|
||||
if (decorator != null)
|
||||
{
|
||||
if (decorator.Child != null)
|
||||
{
|
||||
decorator.Child.IsEnabled = true;
|
||||
}
|
||||
var layer = decorator.AdornerLayer;
|
||||
layer?.Remove(_container);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ namespace HandyControl.Controls
|
||||
{
|
||||
_scrollViewer.ScrollChanged -= ScrollViewer_ScrollChanged;
|
||||
}
|
||||
_scrollViewer = VisualHelper.GetGetChild<System.Windows.Controls.ScrollViewer>(obj);
|
||||
_scrollViewer = VisualHelper.GetChild<System.Windows.Controls.ScrollViewer>(obj);
|
||||
if (_scrollViewer != null)
|
||||
{
|
||||
_scrollViewer.ScrollChanged += ScrollViewer_ScrollChanged;
|
||||
|
||||
@@ -14,8 +14,7 @@ namespace HandyControl.Interactivity
|
||||
|
||||
public UIElement Child
|
||||
{
|
||||
get =>
|
||||
_child;
|
||||
get => _child;
|
||||
set
|
||||
{
|
||||
AddVisualChild(value);
|
||||
|
||||
@@ -3,7 +3,17 @@
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||
|
||||
<Style x:Key="DialogBaseStyle" TargetType="controls:Dialog">
|
||||
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="controls:Dialog">
|
||||
<Border Background="{DynamicResource DarkOpacityBrush}">
|
||||
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -27,18 +27,18 @@ namespace HandyControl.Tools
|
||||
: null;
|
||||
}
|
||||
|
||||
internal static T GetGetChild<T>(DependencyObject d) where T : DependencyObject
|
||||
internal static T GetChild<T>(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<T>(child);
|
||||
var result = GetChild<T>(child);
|
||||
if (result != null) return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user