コード例 #1
0
        private static void IsPressedChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs args)
        {
            CurrentRequestsPanel panel = (CurrentRequestsPanel)depObj;

            if (!panel.IsPressed && panel.Parent != null)
            {
                animate = new ThicknessAnimation()
                {
                    From     = animationClock != null ? (Thickness)animate.GetCurrentValue(animate.From, animate.To, animationClock) : new Thickness(0, 0, 0, 0),
                    To       = new Thickness(-350, 0, 0, 0),
                    Duration = TimeSpan.FromSeconds(0.8)
                };
                animationClock     = animate.CreateClock();
                animate.Completed += (o, s) => {
                    if (!panel.IsPressed)
                    {
                        RemoveUserControl((Panel)LogicalTreeHelper.GetParent(panel), panel);
                    }
                };
                panel.BeginAnimation(MarginProperty, animate);
            }
            else if (panel.IsPressed && panel.Parent != null)
            {
                var parent = (Panel)LogicalTreeHelper.GetParent(panel);
                List <UserControl> userControls = parent.Children.OfType <UserControl>().ToList();
                animate = new ThicknessAnimation()
                {
                    From     = animationClock != null ? (Thickness)animate.GetCurrentValue(animate.From, animate.To, animationClock) : userControls.Count == 1 ? new Thickness(-350, 0, 0, 0) : new Thickness(-700, 0, 0, 0),
                    To       = new Thickness(0, 0, 0, 0),
                    Duration = TimeSpan.FromSeconds(userControls.Count > 1 ? 1 : 0.8)
                };
                animationClock     = animate.CreateClock();
                animate.Completed += (o, s) => {
                    if (userControls.Count > 1)
                    {
                        RemoveUserControl(parent, userControls[0]);
                    }
                };
                panel.BeginAnimation(MarginProperty, animate);
            }
        }