document all code
MODIFY
WalletWasabi.Fluent/ViewModels/Dialog/DialogViewModelBase.cs
WalletWasabi.Fluent/ViewModels/Dialog/DialogViewModelBase.cs
@@ -8,8 +8,16 @@ using WalletWasabi.Fluent.ViewModels.Dialog;
namespace WalletWasabi.Fluent.ViewModels.Dialog
{
+ /// <summary>
+ /// Foundational class for <see cref="DialogViewModelBase{TResult}"/>.
+ /// Don't use this class directly since it doesn't provide the
+ /// functionality required for Dialogs.
+ /// </summary>
public abstract class DialogViewModelBase : ReactiveObject
{
+ /// <summary>
+ /// An instance of <see cref="IDialogHost"/> that owns this dialog.
+ /// </summary>
public IDialogHost DialogHost { get; }
public DialogViewModelBase(IDialogHost dialogHost)

MODIFY
WalletWasabi.Fluent/ViewModels/Dialog/DialogViewModelBase`1.cs
WalletWasabi.Fluent/ViewModels/Dialog/DialogViewModelBase`1.cs
@@ -6,23 +6,48 @@ using System.Threading.Tasks;
namespace WalletWasabi.Fluent.ViewModels.Dialog
{
+ /// <summary>
+ /// Base ViewModel class for Dialogs that returns a value back.
+ /// </summary>
+ /// <typeparam name="TResult">The type of the value to be returned when the dialog is finished.</typeparam>
public abstract class DialogViewModelBase<TResult> : DialogViewModelBase
{
- public abstract void DialogShown(TaskCompletionSource<TResult> tcs);
+ private TaskCompletionSource<TResult> _tcs { get; set; }
+
+ /// <summary>
+ /// Method that is triggered when the dialog
+ /// is to be shown.
+ /// </summary>
+ public abstract void DialogShown();
+
+ /// <summary>
+ /// Method to be called when the dialog is finished
+ /// and ready to pass a value back to the caller.
+ /// </summary>
+ /// <param name="value">The return value of the dialog</param>
+ public void DialogFinished(TResult value)
+ {
+ _tcs.SetResult(value);
+ _tcs = null;
+ }
public DialogViewModelBase(MainViewModel mainViewModel) : base(mainViewModel)
{
}
+ /// <summary>
+ /// Shows the dialog.
+ /// </summary>
+ /// <returns>The value to be returned when the dialog is finished.</returns>
public Task<TResult> ShowDialogAsync()
{
- var tcs = new TaskCompletionSource<TResult>();
+ this._tcs = new TaskCompletionSource<TResult>();
DialogHost.ShowDialog(this);
- DialogShown(tcs);
+ DialogShown();
- return tcs.Task;
+ return _tcs.Task;
}
}
}

MODIFY
WalletWasabi.Fluent/ViewModels/Dialog/IDialogHost.cs
WalletWasabi.Fluent/ViewModels/Dialog/IDialogHost.cs
namespace WalletWasabi.Fluent.ViewModels.Dialog
{
+ /// <summary>
+ /// Interface for ViewModels that can host a modal dialog.
+ /// </summary>
public interface IDialogHost
{
+ /// <summary>
+ /// Close the currently displayed dialog.
+ /// </summary>
void CloseDialog();
+
+ /// <summary>
+ /// Show a dialog from a ViewModel with <see cref="DialogViewModelBase{TResult}"/> as its base.
+ /// </summary>
+ /// <param name="dialogViewModel">The instance of the Dialog ViewModel to be displayed</param>
void ShowDialog<TDialog>(TDialog dialogViewModel) where TDialog : DialogViewModelBase;
+
+ /// <summary>
+ /// The currently active dialog. The modal dialog UI should close when this is null.
+ /// </summary>
DialogViewModelBase CurrentDialog { get; }
}
}
\ No newline at end of file

document all code