ModalDialog
in namespace DotVVM.BusinessPack.Controls
Renders a modal dialog window inside a page.
Usage & Scenarios
Creates a div
element styled as a modal dialog that can be shown or hidden at any time.
When the dialog is displayed, the content behind it is covered by a semi-transparent backdrop and thus cannot be interacted with.
The Business Pack includes also the Window which can display a similar window but keeps the content behind unlocked.
Sample 1: Basic Usage
The content inside the <bp:ModalDialog>
element is treated as a ContentTemplate
property which specifies the main content of the dialog.
The IsDisplayed
property is bound to the bool
property in the viewmodel which controls whether the dialog is shown or hidden. When the user hides the dialog, the property is set to false
automatically.
<bp:ModalDialog IsDisplayed="{value: IsModalDisplayed}">
<p>Hello!</p>
</bp:ModalDialog>
<bp:Button Text="Show Modal Dialog"
Click="{command: IsModalDisplayed = true}" />
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.ModalDialog.sample1
{
public class ViewModel : DotvvmViewModelBase
{
public bool IsModalDisplayed { get; set; }
}
}
Sample 2: Header And Footer
The HeaderText
can be used to specify the text in the dialog header. Alternatively, you can use the HeaderTemplate
property to be able to use any HTML content inside the dialog header.
The same applies to the FooterText
and FooterTemplate
properties which can be used to customize the dialog footer row.
<%-- Custom content with header and footer text --%>
<bp:ModalDialog HeaderText="This is header"
FooterText="This is footer."
IsDisplayed="{value: IsModal1Displayed}">
<p>Display modal dialog content here.</p>
</bp:ModalDialog>
<bp:Button Text="Show Modal Dialog"
Click="{command: IsModal1Displayed = true}" />
<%-- Custom content with header and footer template --%>
<bp:ModalDialog IsDisplayed="{value: IsModal2Displayed}">
<HeaderTemplate>
<h3>This is header</h3>
</HeaderTemplate>
<ContentTemplate>
<p>Display modal dialog content here.</p>
</ContentTemplate>
<FooterTemplate>
<i>This is footer.</i>
</FooterTemplate>
</bp:ModalDialog>
<bp:Button Text="Show templated Modal Dialog"
Click="{command: IsModal2Displayed = true}" />
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.ModalDialog.sample2
{
public class ViewModel : DotvvmViewModelBase
{
public bool IsModal1Displayed { get; set; }
public bool IsModal2Displayed { get; set; }
}
}
Sample 3: Closing Dialog
By default, the dialog can be closed when the user clicks outside it.
The CloseOnOutsideClick
can be used to disable this behavior. If it is set to false
, the dialog will stay open when the user clicks anywhere outside it.
<bp:ModalDialog IsDisplayed="{value: IsModalDisplayed}"
CloseOnOutsideClick="false">
<p>Now you cannot click outside of the dialog to close it.</p>
</bp:ModalDialog>
<bp:Button Text="Show Modal"
Click="{command: IsModalDisplayed = true}" />
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.ModalDialog.sample3
{
public class ViewModel : DotvvmViewModelBase
{
public bool IsModalDisplayed { get; set; }
}
}
Sample 4: Dialog Size
The WidthRequest
and HeightRequest
properties can be used to specify requested dimensions of the dialog (in pixels). If the screen is smaller than the requested size, the dialog will take all available space.
You can fine-tune dialog sizing on various screen sizes using CSS.
<bp:ModalDialog IsDisplayed="{value: IsCustomSizeModalVisible}"
WidthRequest="800"
HeightRequest="300">
<p>I have custom size.</p>
</bp:ModalDialog>
<bp:Button Text="Show Modal Dialog with custom size"
Click="{command: IsCustomSizeModalVisible = true}" />
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.ModalDialog.sample4
{
public class ViewModel : DotvvmViewModelBase
{
public bool IsCustomSizeModalVisible { get; set; }
public bool IsResizableModalVisible { get; set; }
}
}
Properties
Name | Type | Description | Notes | Default Value | |
---|---|---|---|---|---|
AllowResize | Boolean | Gets or sets whether user is allowed to resize the dialog. It's enabled by default. |
attribute
static value
|
True | |
AnimationDuration | Double | Gets or sets how long will the open and close animations run (in seconds). If the value is equal to 0, dialog is not animated. The default value is 0.25 seconds. |
attribute
static value
bindable
|
0.25 | |
Attributes | Dictionary<String,Object> |
attribute
static value
|
null | ||
ClientIDMode | ClientIDMode | Gets or sets the client ID generation algorithm. |
attribute
static value
|
Static | |
CloseOnEscape | Boolean | Gets or sets whether dialog will be closed when user hits the Escape key. It's enabled by default. |
attribute
static value
|
True | |
CloseOnOutsideClick | Boolean | Gets or sets whether dialog will be closed when user clicks outside the dialog. It's enabled by default. |
attribute
static value
|
True | |
ContentTemplate | ITemplate | Gets or sets template for content part of dialog. |
inner element
static value
default
|
null | |
DataContext | Object | Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value. |
attribute
static value
bindable
|
null | |
DeathZoneSize | Int32 | Gets or sets size (in px) of zone around the dialog borders where modal cannot be moved or resized into. The default size is 10px. |
attribute
static value
bindable
|
0 | |
FooterTemplate | ITemplate | Gets or sets the template for the footer part of the dialog. |
inner element
static value
|
null | |
FooterText | String | Gets or sets the text of the footer part of the dialog. This property cannot be combined with the FooterTemplate property. |
attribute
static value
bindable
|
||
HeaderTemplate | ITemplate | Gets or sets the template for the header part of the dialog. |
inner element
static value
|
null | |
HeaderText | String | Gets or sets the text of the header part of the dialog. This property cannot be combined with the HeaderTemplate property. |
attribute
static value
bindable
|
||
Height | String | Gets or sets the height of the dialog. The value uses the CSS syntax, e.g. 640px or 80%. It is not set by default. |
attribute
static value
bindable
|
null | |
ID | String | Gets or sets the unique control ID. |
attribute
static value
bindable
|
null | |
IncludeInPage | Boolean | Gets or sets whether the control is included in the DOM of the page. |
attribute
bindable
|
True | |
InitialPositionBottom | String |
attribute
static value
|
null | ||
InitialPositionLeft | String | Gets or sets initial position from left border. The value uses the CSS syntax, e.g. 200px or 10%. It is not set by default. |
attribute
static value
|
null | |
InitialPositionRight | String |
attribute
static value
|
null | ||
InitialPositionTop | String | Gets or sets initial position from top border. The value uses the CSS syntax, e.g. 200px or 10%. It is not set by default. |
attribute
static value
|
null | |
InnerText | String | Gets or sets the inner text of the HTML element. |
attribute
static value
bindable
|
null | |
IsDisplayed | Boolean | Gets or sets the value indicating whether the dialog is visible. |
attribute
bindable
|
False | |
MinHeight | Int32 | Gets or sets the minimum height of dialog in pixels. The default value is 150. |
attribute
static value
|
150 | |
MinWidth | Int32 | Gets or sets the minimum width of the dialog in pixels. The default value is 250. |
attribute
static value
|
250 | |
ShowOverlay | Boolean | Gets or sets whether an overlay is displayed under the dialog. It's enabled by default. |
attribute
static value
|
True | |
Visible | Boolean | Gets or sets whether the control is visible. |
attribute
bindable
|
True | |
Width | String | Gets or sets the width of the dialog. The value uses the CSS syntax, e.g. 640px or 80%. The default value is 640px. |
attribute
static value
bindable
|
640px |