/// <summary>
                /// Activates the specified item.
                /// </summary>
                /// <param name="item">The item to activate.</param>
                /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
                /// <returns>A task that represents the asynchronous operation.</returns>
                public override async Task ActivateItemAsync(T item, CancellationToken cancellationToken)
                {
                    if (item != null && item.Equals(ActiveItem))
                    {
                        if (IsActive)
                        {
                            await ScreenExtensions.TryActivateAsync(item, cancellationToken);
                        }

                        return;
                    }

                    await ChangeActiveItemAsync(item, false, cancellationToken);
                }
Beispiel #2
0
                /// <summary>
                /// Activates the specified item.
                /// </summary>
                /// <param name="item">The item to activate.</param>
                /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
                /// <returns>A task that represents the asynchronous operation.</returns>
                public override async Task ActivateItemAsync(T item, CancellationToken cancellationToken)
                {
                    if (item == null)
                    {
                        return;
                    }

                    EnsureItem(item);

                    if (IsActive)
                    {
                        await ScreenExtensions.TryActivateAsync(item, cancellationToken);
                    }
                }
                /// <summary>
                /// Called when deactivating.
                /// </summary>
                /// <param name="close">Indicates whether this instance will be closed.</param>
                /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
                /// <returns>A task that represents the asynchronous operation.</returns>
                protected override async Task OnDeactivateAsync(bool close, CancellationToken cancellationToken)
                {
                    if (close)
                    {
                        foreach (var deactivate in _items.OfType <IActivate>())
                        {
                            await deactivate.DeactivateAsync(true, cancellationToken);
                        }

                        _items.Clear();
                    }
                    else
                    {
                        await ScreenExtensions.TryDeactivateAsync(ActiveItem, false, cancellationToken);
                    }
                }
                private async Task CloseItemCoreAsync(T item, CancellationToken cancellationToken)
                {
                    if (item.Equals(ActiveItem))
                    {
                        var index = _items.IndexOf(item);
                        var next  = DetermineNextItemToActivate(_items, index);

                        await ChangeActiveItemAsync(next, true, cancellationToken);
                    }
                    else
                    {
                        await ScreenExtensions.TryDeactivateAsync(item, true, cancellationToken);
                    }

                    _items.Remove(item);
                }
        /// <inheritdoc />
        public override async Task ActivateItemAsync(T item, CancellationToken cancellationToken)
        {
            if (item != null && item.Equals(ActiveItem))
            {
                if (IsActive)
                {
                    await ScreenExtensions.TryActivateAsync(item, cancellationToken);
                }
                return;
            }

            var closeResult = await CloseStrategy.ExecuteAsync(new[] { ActiveItem }, cancellationToken);

            if (closeResult.CloseCanOccur)
            {
                await ChangeActiveItemAsync(item, true, cancellationToken);
            }
        }
Beispiel #6
0
                /// <summary>
                /// Deactivates the specified item.
                /// </summary>
                /// <param name="item">The item to close.</param>
                /// <param name="close">Indicates whether or not to close the item after deactivating it.</param>
                /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
                /// <returns>A task that represents the asynchronous operation.</returns>
                public override async Task DeactivateItemAsync(T item, bool close, CancellationToken cancellationToken)
                {
                    if (item == null)
                    {
                        return;
                    }

                    if (close)
                    {
                        var closeResult = await CloseStrategy.ExecuteAsync(new[] { item }, CancellationToken.None);

                        if (closeResult.CloseCanOccur)
                        {
                            await CloseItemCoreAsync(item, cancellationToken);
                        }
                    }
                    else
                    {
                        await ScreenExtensions.TryDeactivateAsync(item, false, cancellationToken);
                    }
                }
Beispiel #7
0
                private async Task CloseItemCoreAsync(T item, CancellationToken cancellationToken)
                {
                    await ScreenExtensions.TryDeactivateAsync(item, true, cancellationToken);

                    _items.Remove(item);
                }
 /// <summary>
 /// Called when deactivating.
 /// </summary>
 /// <param name="close">Indicates whether this instance will be closed.</param>
 /// <param name="cancellationToken">The cancellation token to cancel operation.</param>
 /// <returns>A task that represents the asynchronous operation.</returns>
 protected override Task OnDeactivateAsync(bool close, CancellationToken cancellationToken)
 {
     return(ScreenExtensions.TryDeactivateAsync(ActiveItem, close, cancellationToken));
 }
 /// <summary>
 /// Called when activating.
 /// </summary>
 /// <returns>A task that represents the asynchronous operation.</returns>
 protected override Task OnActivateAsync(CancellationToken cancellationToken)
 {
     return(ScreenExtensions.TryActivateAsync(ActiveItem, cancellationToken));
 }