Beispiel #1
0
        /// <summary>
        /// starts or stopps the autoclose timer
        /// </summary>
        /// <param name="childWindow"></param>
        /// <param name="e"></param>
        private void OnIsAutoCloseEnabledChanged(ChildWindow childWindow, AvaloniaPropertyChangedEventArgs e)
        {
            void AutoCloseEnabledChangedAction()
            {
                if (e.NewValue != e.OldValue)
                {
                    if ((bool)e.NewValue)
                    {
                        if (childWindow.IsOpen)
                        {
                            childWindow.StartAutoCloseTimer();
                        }
                    }
                    else
                    {
                        childWindow.StopAutoCloseTimer();
                    }
                }
            }

            Dispatcher.UIThread.InvokeAsync((Action)AutoCloseEnabledChangedAction, DispatcherPriority.Background);
        }
Beispiel #2
0
        /// <summary>
        /// starts the open or close animation
        /// </summary>
        /// <param name="childWindow"></param>
        /// <param name="e"></param>
        private void OnIsOpenChanged(ChildWindow childWindow, AvaloniaPropertyChangedEventArgs e)
        {
            //skip other childs to display
            if (childWindow != this)
            {
                return;
            }


            if (Equals(e.OldValue, e.NewValue))
            {
                return;
            }

            if ((bool)e.NewValue)
            {
                if (_hideAnimationTask != null)
                {
                    _hideAnimationTokenSource.Cancel(false);
                    _hideAnimationTokenSource = null;
                    _hideAnimationTask        = null;
                    // don't let the storyboard end it's completed event
                    // otherwise it could be hidden on start
                }

                _showAnimationTask = _showAnimation.RunAsync(childWindow).ContinueWith(
                    x =>
                {
#warning little bit hacky should be done in the animation
                    _partOverlay.IsVisible = true;

                    _showAnimationTask = null;

                    var parent         = childWindow.Parent as Panel;
                    childWindow.ZIndex = /*parent?.Children.Count + 1 ??*/ 99;

                    childWindow.TryToSetFocusedElement();

                    if (childWindow.IsAutoCloseEnabled)
                    {
                        childWindow.StartAutoCloseTimer();
                    }

                    childWindow.RaiseEvent(new RoutedEventArgs(IsOpenChangedEvent, childWindow));
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
            else
            {
                childWindow.StopAutoCloseTimer();

                _hideAnimationTokenSource = new CancellationTokenSource();

                _hideAnimationTask = _hideAnimation.RunAsync(childWindow).ContinueWith(
                    x =>
                {
                    childWindow.OnClosingFinished();
                    _hideAnimationTask = null;

#warning little bit hacky should be done in the animation
                    _partOverlay.IsVisible = false;
                }, _hideAnimationTokenSource.Token,
                    TaskContinuationOptions.None,
                    TaskScheduler.FromCurrentSynchronizationContext());
            }
        }