1

I'm developing a .NET 4.0 application using PRISM and MVVM, as well as WPF.

I currently have a shell subdivided in regions, with views inserted in them. When the user clicks on a button in one of the views, I would like a custom-made modal dialog to be displayed on top of all the views, but still within the same shell.

I looked at the StockTrader RI example and their implementation of the RegionPopupBehavior. Basically, they created a dependency property which allows them to define regions with a specific, custom-made behavior. The behavior is the one in charge of handling it's associated view's rendering, hence displaying it as a popup window.

The only downside to this approach is that all the other views are still active, so the popup isn't modal. I guess this can be resolved by manually disabling all un-needed regions in the shell, but I'm not sure how "clean" this is.

I was wondering if there were a better and simpler approach to displaying modal pop-up views in Prism ?

Hussein Khalil
  • 1,585
  • 2
  • 25
  • 47
  • This is WPF, not Silverlight, right? – Dave Swersky Mar 29 '12 at 15:44
  • 1
    Maybe you could use something like this http://stackoverflow.com/questions/8103743/wpf-c-sharp-inputbox/8103869#8103869 ? I use this with a modified version for MVVM to do the same thing. – eandersson Mar 29 '12 at 16:01
  • 1
    You might be interested in a custom [PopupUserControl](http://rachel53461.wordpress.com/2011/08/20/popup-panel-for-wpf/) I have posted on my blog that behaves like that – Rachel Mar 29 '12 at 16:35
  • @Rachel: This is exactly what I needed, thank you. I plan on binding the popup's content to a UserControl, I guess this will also work ? (Instead of using DataTemplates). – Hussein Khalil Mar 29 '12 at 18:24
  • @HusseinKhalil I posted that as an answer, along with a few examples of how to set the `Content` of the popup. You can bind the `Content` property to a `UserControl`, although if you're using the MVVM design pattern then your ViewModels really shouldn't have any UI objects in them. – Rachel Mar 29 '12 at 18:49

1 Answers1

2

You might be interested in a custom PopupUserControl I have posted on my blog that behaves like that.

Usually I use it like this:

<local:PopupPanel 
    Content="{Binding PopupContent}"
    local:PopupPanel.PopupParent="{Binding ElementName=SomeParentPanel}"
    local:PopupPanel.IsPopupVisible="{Binding IsPopupVisible}">

    <local:PopupPanel.Resources>
        <DataTemplate DataType="{x:Type local:SomeViewModel}">
            <local:SomeView />
        </DataTemplate>
        <DataTemplate DataType="{x:Type local:DifferentViewModel}">
            <local:DifferentView />
        </DataTemplate>
    </local:PopupPanel.Resources>

</local:PopupPanel>

Although you can also just write the Content in the popup instead of binding the Content property

<local:PopupPanel 
    local:PopupPanel.PopupParent="{Binding ElementName=SomeParentPanel}"
    local:PopupPanel.IsPopupVisible="{Binding IsPopupVisible}">

    <Border BorderBrush="Blue" BorderThickness="2">
        <local:MyUserControl />
    </Border>
</local:PopupPanel>
Rachel
  • 130,264
  • 66
  • 304
  • 490
  • Thank you ! You are right about the fact that a ViewModel shouldn't have any UI element in it. I guess the best solution is as you suggested: bind to an object and have data templates... – Hussein Khalil Mar 29 '12 at 19:59