Created
June 14, 2022 10:52
-
-
Save mrpmorris/48dce45a5b04c07a0c67310b113f7575 to your computer and use it in GitHub Desktop.
Example of showing a modal and waiting for a result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Morris.Blazor.Web.Modal.Modal Visible=@IsVisible title="Invite a user" aria-title="Invite a user"> | |
<div class="card p-3 shadow"> | |
<main> | |
<div class="modal-content"> | |
<div class="modal-header card-header pb-2"> | |
<h1 class="modal-title lead font-weight-bold" tabindex="-1">Invite a user</h1> | |
</div> | |
<div class="modal-body p-3"> | |
</div> | |
<div class="modal-footer card-footer"> | |
<button @onclick=OKClicked>OK</button> | |
<button @onclick=CancelClicked>Cancel</button> | |
</div> | |
</div> | |
</main> | |
</div> | |
</Morris.Blazor.Web.Modal.Modal> | |
// Code | |
public partial class Create | |
{ | |
private bool IsVisible; | |
// Use TaskCompletionSource<T> to return a specific type of value | |
private TaskCompletionSource<bool> TaskCompletionSource = new(); | |
public Task ShowAsync() | |
{ | |
TaskCompletionSource = new TaskCompletionSource<bool>(); | |
IsVisible = true; | |
StateHasChanged(); | |
return TaskCompletionSource.Task; | |
} | |
private void OKClicked() | |
{ | |
IsVisible = false; | |
TaskCompletionSource.SetResult(true); | |
} | |
private void CancelClicked() | |
{ | |
IsVisible = false; | |
TaskCompletionSource.SetResult(false); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment