Ejemplo n.º 1
0
        /// <summary>
        /// Shows the dialog on the next render after a show action. Also on the next render after the dialog is initiated each
        /// embedded Material.Blazor component is initiated here.
        /// </summary>
        /// <param name="firstRender"></param>
        /// <returns></returns>
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            await base.OnAfterRenderAsync(firstRender);

            if (AfterRenderShowAction)
            {
                try
                {
                    AfterRenderShowAction = false;
                    Tcs.SetResult(await JsRuntime.InvokeAsync <string>("material_blazor.dialog.show", DialogElem, ObjectReference, EscapeKeyAction, ScrimClickAction));
                    IsOpen = false;
                    StateHasChanged();
                }
                catch
                {
                    Tcs?.SetCanceled();
                }
            }
            else if (AfterDialogInitialization)
            {
                AfterDialogInitialization = false;

                foreach (var child in LayoutChildren)
                {
                    child.RequestInstantiation();
                }

                LayoutChildren.Clear();

                hasInstantiated = true;

                StateHasChanged();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Shows the dialog. This first renders the Blazor markup and then allows
 /// Material Theme to open the dialog, subsequently intiating all embedded Blazor components.
 /// </summary>
 /// <returns>The action string resulting form dialog closure</returns>
 public async Task <string> ShowAsync()
 {
     if (IsOpen)
     {
         throw new InvalidOperationException("Cannot show MBDialog that is already open");
     }
     else
     {
         LayoutChildren.Clear();
         Key    = Utilities.GenerateUniqueElementName();
         IsOpen = true;
         AfterRenderShowAction = true;
         StateHasChanged();
         Tcs = new TaskCompletionSource <string>();
         var ret = await Tcs.Task;
         hasInstantiated = false;
         return(ret);
     }
 }