Class Dialog
Attached behavior. Displays a Window based on an implementation of IDialogViewModel assigned to the attached property DialogDataContextProperty and a custom DataTemplate.
Inherited Members
Namespace: BionicCode.Utilities.Net
Assembly: BionicCode.Utilities.Net.Wpf.dll
Syntax
public class Dialog : DependencyObject
Remarks
This attached behavior will display a dialog Window using the View-model-first pattern.
The IDialogViewModel instance bound to the DialogDataContextProperty will be assigned to the Content of the Window. To layout the content requires to define an implicit DataTemplate that targets the type of the IDialogViewModel implementation. Alternatively set the template for the ContentTemplate via a Style that targets Window and is assigned to the StyleProperty attached property. For more complex scenarios it is possible to assign a DataTemplateSelector to the DataTemplateSelectorProperty attached property.
To define the attributes like title and icon of the dialog, set the corresponding values of the IDialogViewModel implementation. Dialog sets up a data binding to those properties, so that they can be dynamically changed by the view model.
It is recommended to use and extend the abstract DialogViewModel, which provides the basic IDialogViewModel implementation and logic. It only needs to be extended to provide the required specific properties for the dialog's context.
To show a dialog, simply assign an instance of IDialogViewModel to the attached property DialogDataContextProperty. A change of that property will automatically display a new dialog window. To each IDialogViewModel maps an instance of Window. It is recommended to bind the attached DialogDataContextProperty to a property of a view model class that implements INotifyPropertyChanged. This way it is very simple to display dialogs dynamically initiated by the view model i.e. the binding source of the attached DialogDataContextProperty property.
To close a dialog, raise the InteractionCompleted event from the IDialogViewModel implementation e.g., by calling OnInteractionCompleted() or by invoking the SendResponseAsyncCommand (in case you followed the recommendation to extend DialogViewModel).
Fields
| Improve this Doc View SourceDataTemplateSelectorProperty
Attached property to set a DataTemplateSelector to use for the displayed dialog Window to display the content.
Declaration
public static readonly DependencyProperty DataTemplateSelectorProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
DialogDataContextProperty
Attached property designed to bind to a view model property of type IDialogViewModel. A change of this property will trigger the Dialog to show a Window with the DataContext set to the IDialogViewModel instance of this property.
Declaration
public static readonly DependencyProperty DialogDataContextProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
IsClosableProperty
Attached property that controls if the user is allowed to explicitly close the Window.
Declaration
public static readonly DependencyProperty IsClosableProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
IsModalProperty
Attached property that controls if the Window is shown modal.
Declaration
public static readonly DependencyProperty IsModalProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
StyleProperty
The attached Style property which holds the Style which should apply to the dialog. TargetType must be Window.
Declaration
public static readonly DependencyProperty StyleProperty
Field Value
| Type | Description |
|---|---|
| DependencyProperty |
Methods
| Improve this Doc View SourceGetDataTemplateSelector(DependencyObject)
Returns the DataTemplateSelector registered with the attachingElement.
Declaration
public static DataTemplateSelector GetDataTemplateSelector(DependencyObject attachingElement)
Parameters
| Type | Name | Description |
|---|---|---|
| DependencyObject | attachingElement | The attached FrameworkElement. |
Returns
| Type | Description |
|---|---|
| DataTemplateSelector | The DataTemplateSelector registered with the |
GetDialogDataContext(DependencyObject)
The getter for the attached DialogDataContextProperty property.
Declaration
public static IDialogViewModel GetDialogDataContext(DependencyObject attachingElement)
Parameters
| Type | Name | Description |
|---|---|---|
| DependencyObject | attachingElement | The attached FrameworkElement. |
Returns
| Type | Description |
|---|---|
| IDialogViewModel | The current associated IDialogViewModel. |
GetIsClosable(DependencyObject)
Get method of the attached property IsClosableProperty.
Declaration
public static bool GetIsClosable(DependencyObject attachingElement)
Parameters
| Type | Name | Description |
|---|---|---|
| DependencyObject | attachingElement | The attached FrameworkElement. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
GetIsModal(DependencyObject)
Get method of the attached property IsModalProperty.
Declaration
public static bool GetIsModal(DependencyObject attachingElement)
Parameters
| Type | Name | Description |
|---|---|---|
| DependencyObject | attachingElement | The attached FrameworkElement. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
GetStyle(DependencyObject)
Get method of the attached property StyleProperty.
Declaration
public static Style GetStyle(DependencyObject attachingElement)
Parameters
| Type | Name | Description |
|---|---|---|
| DependencyObject | attachingElement | The attached FrameworkElement. |
Returns
| Type | Description |
|---|---|
| Style | The dialog's Style registered with the |
SetDataTemplateSelector(DependencyObject, DataTemplateSelector)
Set method of the attached DataTemplateSelectorProperty property.
Declaration
public static void SetDataTemplateSelector(DependencyObject attachingElement, DataTemplateSelector value)
Parameters
| Type | Name | Description |
|---|---|---|
| DependencyObject | attachingElement | The attached FrameworkElement. |
| DataTemplateSelector | value | A DataTemplateSelector implementation for the window's content. |
SetDialogDataContext(DependencyObject, IDialogViewModel)
The setter for the attached DialogDataContextProperty property.
Declaration
public static void SetDialogDataContext(DependencyObject attachingElement, IDialogViewModel value)
Parameters
| Type | Name | Description |
|---|---|---|
| DependencyObject | attachingElement | The attached FrameworkElement. |
| IDialogViewModel | value | An instance of IDialogViewModel. |
SetIsClosable(DependencyObject, Boolean)
Set method of the IsClosableProperty attached property.
Declaration
public static void SetIsClosable(DependencyObject attachingElement, bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| DependencyObject | attachingElement | The attached FrameworkElement. |
| Boolean | value |
|
SetIsModal(DependencyObject, Boolean)
Set method of the IsModalProperty attached property.
Declaration
public static void SetIsModal(DependencyObject attachingElement, bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| DependencyObject | attachingElement | The attached FrameworkElement. |
| Boolean | value |
|
SetStyle(DependencyObject, Style)
Set method of the attached property StyleProperty.
Declaration
public static void SetStyle(DependencyObject attachingElement, Style value)
Parameters
| Type | Name | Description |
|---|---|---|
| DependencyObject | attachingElement | The attached FrameworkElement. |
| Style | value |
TryGetDialog(IDialogViewModel, out Window)
Attempts to get the dialog Window of the associated IDialogViewModel instance.
Declaration
public static bool TryGetDialog(IDialogViewModel viewModel, out Window dialog)
Parameters
| Type | Name | Description |
|---|---|---|
| IDialogViewModel | viewModel | The associated data context of the dialog. |
| Window | dialog | The Window instance associated with the |
Returns
| Type | Description |
|---|---|
| Boolean |
|