示例#1
0
        internal async Task CloseSubMenuAsync(SubMenuOption option)
        {
            await option.SubMenu.TopMenu.SemaphoreSlim.WaitAsync();

            try
            {
                if (!option.IsShow)
                {
                    return;
                }
                option.IsShow = false;
                if (GlobalElementSettings.DisableAnimation)
                {
                    await InvokeAsync(option.SubMenu.DeActivate);

                    PopupService.SubMenuOptions.Remove(option);
                    return;
                }
                await InvokeAsync(StateHasChanged);

                await Task.Delay(200);
                await InvokeAsync(option.SubMenu.DeActivate);

                PopupService.SubMenuOptions.Remove(option);
            }
            finally
            {
                option.SubMenu.TopMenu.SemaphoreSlim.Release();
            }
        }
示例#2
0
        protected async Task OnOverAsync()
        {
            if (TopMenu.Mode == MenuMode.Horizontal)
            {
                await SemaphoreSlim.WaitAsync();

                try
                {
                    if (IsOpened)
                    {
                        try
                        {
                            if (subMenuOption != null &&
                                subMenuOption.ClosingTask != null &&
                                subMenuOption.ClosingTask.Status != TaskStatus.RanToCompletion &&
                                subMenuOption.ClosingTask.Status != TaskStatus.Canceled)
                            {
                                subMenuOption.ClosingTaskCancellationTokenSource.Cancel();
                            }
                        }
                        catch (ObjectDisposedException)
                        {
                        }
                        return;
                    }
                    subMenuOption = new SubMenuOption()
                    {
                        SubMenu = this,
                        Content = ChildContent,
                        Options = Options,
                        Target  = Element
                    };
                    var taskCompletionSource = new TaskCompletionSource <int>();
                    subMenuOption.TaskCompletionSource = taskCompletionSource;
                    while (PopupService.SubMenuOptions.Any())
                    {
                        await Task.Delay(50);
                    }
                    PopupService.SubMenuOptions.Add(subMenuOption);
                    IsOpened = true;
                }
                finally
                {
                    SemaphoreSlim.Release();
                }
                await subMenuOption.TaskCompletionSource.Task;
                borderColor = "transparent";

                IsOpened = false;
                await OnOutAsync();
            }
            else
            {
                backgroundColor = Options.HoverColor;
                textColor       = Options.ActiveTextColor;
                isActive        = true;
            }
        }
示例#3
0
        internal async Task ReadyCloseSubMenuAsync(SubMenuOption option)
        {
            option.ClosingTaskCancellationTokenSource = new System.Threading.CancellationTokenSource();
            var task = Task.Delay(200, option.ClosingTaskCancellationTokenSource.Token).ContinueWith(async task =>
            {
                if (task.IsCanceled)
                {
                    DisposeTokenSource(option.ClosingTaskCancellationTokenSource);
                    return;
                }
                DisposeTokenSource(option.ClosingTaskCancellationTokenSource);
                await CloseSubMenuAsync(option);
            });

            option.ClosingTask = await task;
        }
示例#4
0
 internal void KeepShowSubMenu(SubMenuOption option)
 {
     CancelTokenSource(option.ClosingTaskCancellationTokenSource);
 }