Class DialogViewModel
Implementation of IDialogViewModel. This abstract class implements the dialog data handling logic and is therefore preferred over a custom implementation of IDialogViewModel.
Implements
Inherited Members
Namespace: BionicCode.Utilities.Net
Assembly: BionicCode.Utilities.Net.Wpf.dll
Syntax
public abstract class DialogViewModel : ViewModel, IDialogViewModel, IViewModel, IProgressReporter, IViewModelCommon, INotifyDataErrorInfo, IProgressReporterCommon, INotifyPropertyChanged
Remarks
It is recommended to use the Dialog attached behavior as it handles the view logic. Just bind DialogDataContextProperty to an instance of DialogViewModel (or IDialogViewModel) and define a DataTemplate for each implementation of DialogViewModel.
Constructors
| Improve this Doc View SourceDialogViewModel(String, String)
Creates a nw instance of the DialogViewModel using a do-nothing dialog closed callback.
Declaration
protected DialogViewModel(string message, string title)
Parameters
| Type | Name | Description |
|---|---|---|
| String | message | The dialog message to sow. |
| String | title | The dialog caption to appear in the title bar of the Window. |
DialogViewModel(String, String, Func<IDialogViewModel, Task>)
Creates a nw instance of the DialogViewModel registering a dialog closed callback.
Declaration
protected DialogViewModel(string message, string title, Func<IDialogViewModel, Task> sendResponseCallbackAsync)
Parameters
| Type | Name | Description |
|---|---|---|
| String | message | The dialog message to sow. |
| String | title | The dialog caption to appear in the title bar of the Window. |
| Func<IDialogViewModel, Task> | sendResponseCallbackAsync | The call back to invoke when the dialog was closed |
DialogViewModel(String, String, ImageSource, Func<IDialogViewModel, Task>)
Creates a nw instance of the DialogViewModel registering a dialog closed callback.
Declaration
protected DialogViewModel(string message, string title, ImageSource titleBarIcon, Func<IDialogViewModel, Task> sendResponseCallbackAsync)
Parameters
| Type | Name | Description |
|---|---|---|
| String | message | The dialog message to sow. |
| String | title | The dialog caption to appear in the title bar of the Window. |
| ImageSource | titleBarIcon | The ImageSource for the window's title icon. |
| Func<IDialogViewModel, Task> | sendResponseCallbackAsync | The call back to invoke when the dialog was closed |
Properties
| Improve this Doc View SourceDialogResult
The DialogResult of the user interaction.
Declaration
public DialogResult DialogResult { get; set; }
Property Value
| Type | Description |
|---|---|
| DialogResult |
Message
The message for the dialog to show to the user.
Declaration
public string Message { get; set; }
Property Value
| Type | Description |
|---|---|
| String |
ResponseCallbackAsync
The asynchronous callback that is invoked during the dialog interaction. Use this callback as continuation of the interrupted flow, after the required data was collected by the dialog.
Declaration
public Func<IDialogViewModel, Task> ResponseCallbackAsync { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<IDialogViewModel, Task> |
Remarks
When using the abstract class DialogViewModel this delegate is invoked when invoking the SendResponseAsyncCommand. The parameter of this callback is the original IDialogViewModel. The callback can access the DialogResult property to get the interaction result. The ResponseCallbackAsync makes the dialog interaction fire-and-forget as the IDialogViewModelProviderSource doesn't need to wait for the dialog to close and doesn't have to store a reference to the IDialogViewModel.
SendResponseAsyncCommand
ICommand that can be bound to the buttons of the dialog. The command parameter is a DialogResult.
Declaration
public IAsyncRelayCommand<DialogResult> SendResponseAsyncCommand { get; }
Property Value
| Type | Description |
|---|---|
| IAsyncRelayCommand<DialogResult> |
Remarks
When using the abstract class DialogViewModel the SendResponseAsyncCommand sets the DialogResult property and invokes the ResponseCallbackAsync continuation callback. The parameter of this callback is the original IDialogViewModel. The callback can access the DialogResult property to get the interaction result. The ResponseCallbackAsync makes the dialog interaction fire-and-forget as the IDialogViewModelProviderSource doesn't need to wait for the dialog to close and doesn't have to store a reference to the IDialogViewModel.
Title
The title of the dialog Window
Declaration
public string Title { get; set; }
Property Value
| Type | Description |
|---|---|
| String |
TitleBarIcon
The icon to display in the title bar of the Window
Declaration
public ImageSource TitleBarIcon { get; set; }
Property Value
| Type | Description |
|---|---|
| ImageSource |
Methods
| Improve this Doc View SourceCanExecuteSendResponseCommand(DialogResult)
Declaration
protected virtual bool CanExecuteSendResponseCommand(DialogResult commandParameter)
Parameters
| Type | Name | Description |
|---|---|---|
| DialogResult | commandParameter |
Returns
| Type | Description |
|---|---|
| Boolean |
ExecuteSendResponseCommandAsync(DialogResult)
Asynchronously called when the SendResponseAsyncCommand is executed.
Declaration
protected virtual async Task ExecuteSendResponseCommandAsync(DialogResult result)
Parameters
| Type | Name | Description |
|---|---|---|
| DialogResult | result | A DialogResult value that was received by the ICommand. |
Returns
| Type | Description |
|---|---|
| Task | A |
OnInteractionCompleted()
Event invocator of the InteractionCompleted event. Raising this event will request the dialog to be closed.
Declaration
protected virtual void OnInteractionCompleted()
OnInteractionCompleting(CancelEventArgs)
Event invocator of the InteractionCompleting event. Raised before InteractionCompleted event. When overriding the member, setting the property Cancel of the cancelEventArgs parameter to true will cancel the dialog close process.
Declaration
protected virtual void OnInteractionCompleting(CancelEventArgs cancelEventArgs)
Parameters
| Type | Name | Description |
|---|---|---|
| CancelEventArgs | cancelEventArgs | When setting the property Cancel of the event's CancelEventArgs to |
Remarks
When the dialog close process was cancelled e.g., by overriding the OnInteractionCompleting(CancelEventArgs) method and by setting the cancelEventArgs to true, a new close process can be triggered either by invoking the OnInteractionCompleted() method or by invoking the SendResponseAsyncCommand.
Events
| Improve this Doc View SourceInteractionCompleted
Event to signal that the interaction with the dialog is completed.
Declaration
public event EventHandler InteractionCompleted
Event Type
| Type | Description |
|---|---|
| EventHandler |
Remarks
When extending the abstract class DialogViewModel (instead of the IDialogViewModel interface) together with the attached property DialogDataContextProperty raising this event will notify the Dialog attached behavior class to close the Window.
InteractionCompleting
Event is raised before InteractionCompleted event. Setting the property Cancel of the CancelEventArgs event argument to true will cancel the dialog close process.
Declaration
public event EventHandler<CancelEventArgs> InteractionCompleting
Event Type
| Type | Description |
|---|---|
| EventHandler<CancelEventArgs> |