fix: close #1743
This commit is contained in:
1 parent
2b35e4bdaf
commit
6f72c2f914
1 file changed
+18
-31
@@ -17,23 +17,14 @@ namespace HandyControl.Controls;
|
||||
public class Drawer : FrameworkElement
|
||||
{
|
||||
private Storyboard _storyboard;
|
||||
|
||||
private AdornerContainer _container;
|
||||
|
||||
private ContentControl _animationControl;
|
||||
|
||||
private TranslateTransform _translateTransform;
|
||||
|
||||
private double _animationLength;
|
||||
|
||||
private string _animationPropertyName;
|
||||
|
||||
private FrameworkElement _maskElement;
|
||||
|
||||
private AdornerLayer _layer;
|
||||
|
||||
private UIElement _contentElement;
|
||||
|
||||
private Point _contentRenderTransformOrigin;
|
||||
|
||||
static Drawer()
|
||||
@@ -59,7 +50,8 @@ public class Drawer : FrameworkElement
|
||||
private static void DataContextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
|
||||
((Drawer) d).OnDataContextPropertyChanged(e);
|
||||
|
||||
private void OnDataContextPropertyChanged(DependencyPropertyChangedEventArgs e) => UpdateDataContext(_animationControl, e.OldValue, e.NewValue);
|
||||
private void OnDataContextPropertyChanged(DependencyPropertyChangedEventArgs e) =>
|
||||
UpdateDataContext(_animationControl, e.OldValue, e.NewValue);
|
||||
|
||||
public static readonly RoutedEvent OpenedEvent =
|
||||
EventManager.RegisterRoutedEvent("Opened", RoutingStrategy.Bubble,
|
||||
@@ -82,7 +74,9 @@ public class Drawer : FrameworkElement
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register(
|
||||
nameof(IsOpen), typeof(bool), typeof(Drawer), new FrameworkPropertyMetadata(ValueBoxes.FalseBox, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsOpenChanged));
|
||||
nameof(IsOpen), typeof(bool), typeof(Drawer),
|
||||
new FrameworkPropertyMetadata(ValueBoxes.FalseBox, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||
OnIsOpenChanged));
|
||||
|
||||
private static void OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
@@ -218,7 +212,8 @@ public class Drawer : FrameworkElement
|
||||
|
||||
_animationControl.DataContext = DataContext;
|
||||
_animationControl.CommandBindings.Clear();
|
||||
_animationControl.CommandBindings.Add(new CommandBinding(ControlCommands.Close, (s, e) => SetCurrentValue(IsOpenProperty, ValueBoxes.FalseBox)));
|
||||
_animationControl.CommandBindings.Add(new CommandBinding(ControlCommands.Close,
|
||||
(s, e) => SetCurrentValue(IsOpenProperty, ValueBoxes.FalseBox)));
|
||||
panel.Children.Add(_animationControl);
|
||||
_container = new AdornerContainer(_layer)
|
||||
{
|
||||
@@ -248,31 +243,20 @@ public class Drawer : FrameworkElement
|
||||
return;
|
||||
}
|
||||
|
||||
AdornerDecorator decorator;
|
||||
var parent = VisualHelper.GetParent<DrawerContainer>(this);
|
||||
if (parent != null)
|
||||
AdornerDecorator decorator = VisualHelper.GetParent<DrawerContainer>(this);
|
||||
decorator ??= VisualHelper.GetChild<AdornerDecorator>(System.Windows.Window.GetWindow(this));
|
||||
if (decorator == null)
|
||||
{
|
||||
_contentElement = parent.Child;
|
||||
decorator = parent;
|
||||
}
|
||||
else
|
||||
{
|
||||
var window = WindowHelper.GetActiveWindow();
|
||||
if (window == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
decorator = VisualHelper.GetChild<AdornerDecorator>(window);
|
||||
_contentElement = window.Content as UIElement;
|
||||
return;
|
||||
}
|
||||
|
||||
_contentElement = decorator.Child;
|
||||
if (_contentElement == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_layer = decorator?.AdornerLayer;
|
||||
_layer = decorator.AdornerLayer;
|
||||
if (_layer == null)
|
||||
{
|
||||
return;
|
||||
@@ -328,6 +312,7 @@ public class Drawer : FrameworkElement
|
||||
Storyboard.SetTargetProperty(drawerAnimation, new PropertyPath(_animationPropertyName));
|
||||
_storyboard.Children.Add(drawerAnimation);
|
||||
}
|
||||
|
||||
_storyboard.Begin();
|
||||
}
|
||||
|
||||
@@ -380,7 +365,8 @@ public class Drawer : FrameworkElement
|
||||
? AnimationHelper.CreateAnimation(.9)
|
||||
: AnimationHelper.CreateAnimation(1);
|
||||
Storyboard.SetTarget(animationX, _contentElement);
|
||||
Storyboard.SetTargetProperty(animationX, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleX)"));
|
||||
Storyboard.SetTargetProperty(animationX,
|
||||
new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleX)"));
|
||||
|
||||
_storyboard.Children.Add(animationX);
|
||||
|
||||
@@ -388,7 +374,8 @@ public class Drawer : FrameworkElement
|
||||
? AnimationHelper.CreateAnimation(.9)
|
||||
: AnimationHelper.CreateAnimation(1);
|
||||
Storyboard.SetTarget(animationY, _contentElement);
|
||||
Storyboard.SetTargetProperty(animationY, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleY)"));
|
||||
Storyboard.SetTargetProperty(animationY,
|
||||
new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleY)"));
|
||||
|
||||
_storyboard.Children.Add(animationY);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user