Showing view in a DialogBox

Topics: Prism v4 - WPF 4
Mar 31, 2012 at 7:19 PM


wondering if there's any guidance/sample on showing a view in a dialog window ? used to be possible in CAB so am sure it's possible in PRISM v4 as well

Found some references for dialog windows in StockTrader RI but haven't seen it in the WPF edition




Apr 3, 2012 at 5:40 PM


I believe, you might find the WindowDialogActivationBehavior (for WPF) or the PopupDialogActivationBehavior (for Silverlight) included with the Stock Trader RI useful for this. Those behaviors allows you to define a region that, when a view is added to it, will be shown in a new window/popup.

For more information on this topic, you could take a look at the following code files (in the WPF version of the RI):

  • StockTraderRI_Desktop\StockTraderRI.Infrastructure\Behaviors\RegionPopupBehavior.cs
  • StockTraderRI_Desktop\StockTraderRI.Infrastructure\Behaviors\WindowsDialogActivationBehavior.cs

Additionally you could find a small sample that portrays the implementation of this behavior in the following thread:

I hope you find this handy,

Agustin Adami

Apr 4, 2012 at 3:52 AM

That's great, I see the size is defined in code, Is there a way to make it generic ?

Sorry, i don't quite understand how the behaviors work yet !



Apr 4, 2012 at 4:41 AM

Also, looking at other alternatives here, is there any advantage to using the RegionBehaviour approach as compared to say


      bool? showDialog(UserControl instance, string title, bool resize)
            DialogHost dlg = new DialogHost(); 

           dlg.Content = instance;
            dlg.Owner = this;
            dlg.Title = title;
            dlg.ResizeMode = resize ? ResizeMode.CanResize : System.Windows.ResizeMode.NoResize;
            return dlg.ShowDialog();

where DialogHost is simply

<Window x:Class="MyApplication8.DialogHost"
        Title="DialogHost" Height="300" Width="300"
        SizeToContent="WidthAndHeight" WindowStartupLocation="CenterOwner" Topmost="True" ResizeMode="CanResizeWithGrip">

just wondering !

Apr 4, 2012 at 7:12 PM


As far as I know, if you want to avoid defining the size in code in order to make it more flexible to its content size, you could try for example, instead of defining the Height and Width manually, modifying the WindowWrapper class, by adding the following line to its Show method:

public void Show()
        //Specifies that a window will automatically set both its width and height
        //to fit the width and height of its content.
            this.window.SizeToContent = SizeToContent.WidthAndHeight;

In my opinion the main benefit of using this approach is that it allows you to loosely compose the UI, as you will be able to show a dialog using the UI functionalities provided by Prism through the use of Regions.

On the other hand, also another alternative if you need to need to notify the user of the occurrence of an event, for example by displaying a dialog, could be using InteractionRequests.

You can find more information about this approach in the following chapter of the Prism documentation at MSDN:

Additionally, you can find a WPF sample that portrays the use of InteractionRequest to display a dialog in Karl Shifflet's In The Box MVVM Training (in the MVVM Scenarios Section).

I hope you find this handy,

Agustin Adami