Skip to content

Instantly share code, notes, and snippets.

@mrpmorris
Created June 14, 2022 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrpmorris/48dce45a5b04c07a0c67310b113f7575 to your computer and use it in GitHub Desktop.
Save mrpmorris/48dce45a5b04c07a0c67310b113f7575 to your computer and use it in GitHub Desktop.
Example of showing a modal and waiting for a result
<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