Saturday, November 8, 2014

Prism - Custom PopupWindowAction

One of the nice features in the Prism is the interaction request pattern supported by the InteractionRequest class. I'll quickly provide a brief overview here. In your view model, you can define properties of type InteractionRequest<INotification> and InteractionRequest<IConfirmation>. In your view you bind to a blend interaction trigger with an action of type PopupWindowAction. Manipulating the InteractionRequest from the view model will trigger the PopupWindowAction, showing you pop-up window. This is a neat way to show dialogs while still adhering to the MVVM pattern for testability.

If you do not set the WindowContent property of the PopupWindowAction class, then the DefaultConfirmationWindow or DefaultNotificationWindow will be displayed. These windows are very basic. In fact, they don't have text wrapping. In my application, I mainly use them to display messages to the user. Without text wrapping, messages shown in the DefaultNotifiactionWindow were truncated.

The WindowContent property can be used to show custom content declared in a user control. Here is a custom user control where I've defined a TextBlock with text wrapping. Note that in the .xaml.cs of the user control, I implement the IInteractionRequestAware interface. This will provide the FinishAction and Notification properties, which the control will use.
Often, I favor having a window factor for more complex windows, however, for simple dialog's and interactions this works very well.

1 comment: