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
|
public class Drawer : FrameworkElement
|
||||||
{
|
{
|
||||||
private Storyboard _storyboard;
|
private Storyboard _storyboard;
|
||||||
|
|
||||||
private AdornerContainer _container;
|
private AdornerContainer _container;
|
||||||
|
|
||||||
private ContentControl _animationControl;
|
private ContentControl _animationControl;
|
||||||
|
|
||||||
private TranslateTransform _translateTransform;
|
private TranslateTransform _translateTransform;
|
||||||
|
|
||||||
private double _animationLength;
|
private double _animationLength;
|
||||||
|
|
||||||
private string _animationPropertyName;
|
private string _animationPropertyName;
|
||||||
|
|
||||||
private FrameworkElement _maskElement;
|
private FrameworkElement _maskElement;
|
||||||
|
|
||||||
private AdornerLayer _layer;
|
private AdornerLayer _layer;
|
||||||
|
|
||||||
private UIElement _contentElement;
|
private UIElement _contentElement;
|
||||||
|
|
||||||
private Point _contentRenderTransformOrigin;
|
private Point _contentRenderTransformOrigin;
|
||||||
|
|
||||||
static Drawer()
|
static Drawer()
|
||||||
@@ -59,7 +50,8 @@ public class Drawer : FrameworkElement
|
|||||||
private static void DataContextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
|
private static void DataContextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
|
||||||
((Drawer) d).OnDataContextPropertyChanged(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 =
|
public static readonly RoutedEvent OpenedEvent =
|
||||||
EventManager.RegisterRoutedEvent("Opened", RoutingStrategy.Bubble,
|
EventManager.RegisterRoutedEvent("Opened", RoutingStrategy.Bubble,
|
||||||
@@ -82,7 +74,9 @@ public class Drawer : FrameworkElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register(
|
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)
|
private static void OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
@@ -218,7 +212,8 @@ public class Drawer : FrameworkElement
|
|||||||
|
|
||||||
_animationControl.DataContext = DataContext;
|
_animationControl.DataContext = DataContext;
|
||||||
_animationControl.CommandBindings.Clear();
|
_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);
|
panel.Children.Add(_animationControl);
|
||||||
_container = new AdornerContainer(_layer)
|
_container = new AdornerContainer(_layer)
|
||||||
{
|
{
|
||||||
@@ -248,31 +243,20 @@ public class Drawer : FrameworkElement
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AdornerDecorator decorator;
|
AdornerDecorator decorator = VisualHelper.GetParent<DrawerContainer>(this);
|
||||||
var parent = VisualHelper.GetParent<DrawerContainer>(this);
|
decorator ??= VisualHelper.GetChild<AdornerDecorator>(System.Windows.Window.GetWindow(this));
|
||||||
if (parent != null)
|
if (decorator == null)
|
||||||
{
|
{
|
||||||
_contentElement = parent.Child;
|
return;
|
||||||
decorator = parent;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var window = WindowHelper.GetActiveWindow();
|
|
||||||
if (window == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
decorator = VisualHelper.GetChild<AdornerDecorator>(window);
|
|
||||||
_contentElement = window.Content as UIElement;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_contentElement = decorator.Child;
|
||||||
if (_contentElement == null)
|
if (_contentElement == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_layer = decorator?.AdornerLayer;
|
_layer = decorator.AdornerLayer;
|
||||||
if (_layer == null)
|
if (_layer == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -328,6 +312,7 @@ public class Drawer : FrameworkElement
|
|||||||
Storyboard.SetTargetProperty(drawerAnimation, new PropertyPath(_animationPropertyName));
|
Storyboard.SetTargetProperty(drawerAnimation, new PropertyPath(_animationPropertyName));
|
||||||
_storyboard.Children.Add(drawerAnimation);
|
_storyboard.Children.Add(drawerAnimation);
|
||||||
}
|
}
|
||||||
|
|
||||||
_storyboard.Begin();
|
_storyboard.Begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +365,8 @@ public class Drawer : FrameworkElement
|
|||||||
? AnimationHelper.CreateAnimation(.9)
|
? AnimationHelper.CreateAnimation(.9)
|
||||||
: AnimationHelper.CreateAnimation(1);
|
: AnimationHelper.CreateAnimation(1);
|
||||||
Storyboard.SetTarget(animationX, _contentElement);
|
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);
|
_storyboard.Children.Add(animationX);
|
||||||
|
|
||||||
@@ -388,7 +374,8 @@ public class Drawer : FrameworkElement
|
|||||||
? AnimationHelper.CreateAnimation(.9)
|
? AnimationHelper.CreateAnimation(.9)
|
||||||
: AnimationHelper.CreateAnimation(1);
|
: AnimationHelper.CreateAnimation(1);
|
||||||
Storyboard.SetTarget(animationY, _contentElement);
|
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);
|
_storyboard.Children.Add(animationY);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user