title: How to open new modal dialog using prism in wpf
body: <p>I have done opening the modal dialog in Wpf MVVM. But I am new to prism. I have tried the following code in MVVM. Now its working fine. But I want to do the same concept using prism with ribbon window. In the below code I have not used ribbon window, instead of ribbon window I used the button. please refer the below code,</p>
  
  <p><strong>MainWindow.xaml</strong></p>
  
  <pre><code>   &lt;Window.Resources&gt;
          &lt;DataTemplate DataType="{x:Type vm:ModalDialogViewModel}"&gt;
              &lt;view:ModalDialog /&gt;
          &lt;/DataTemplate&gt;
      &lt;/Window.Resources&gt; 
  
      &lt;Grid&gt;
          &lt;Grid HorizontalAlignment="Stretch" VerticalAlignment="Center"&gt;
              &lt;Grid&gt;               
                  &lt;Button
                      Width="150"
                      Height="25"
                      Margin="0,10,0,0"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      Command="{Binding Path=LoadViewCommand}"
                      Content="Show Modal Dialog" /&gt;                             
              &lt;/Grid&gt;
          &lt;/Grid&gt;
  
          &lt;Grid Visibility="{Binding IsCloseModalWindow, Converter={StaticResource BooleanToVisibilityConverter}}"&gt;
              &lt;Border Background="#90000000"&gt;
                  &lt;Border
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      Background="White"
                      BorderBrush="Transparent"
                      BorderThickness="0"
                      CornerRadius="0"&gt;
                      &lt;Border.BitmapEffect&gt;
                          &lt;DropShadowBitmapEffect
                              Direction="270"
                              Opacity="0.5"
                              ShadowDepth="0.7"
                              Color="Black" /&gt;
                      &lt;/Border.BitmapEffect&gt;
  
                      &lt;ContentControl Content="{Binding Path=CurrentViewModel}" /&gt;
                  &lt;/Border&gt;
              &lt;/Border&gt;
          &lt;/Grid&gt;
      &lt;/Grid&gt; 
  </code></pre>
  
  <p><strong>MainWindowViewModel</strong></p>
  
  <pre><code>public class MainWindowViewModel : ViewModelBase, ICloseWindow
      {
          private ICommand loadViewCommand;
  
          private ViewModelBase _currentViewModel;
  
          public ViewModelBase CurrentViewModel
          {
              get { return _currentViewModel; }
              set
              {
                  _currentViewModel = value;
                  this.OnPropertyChanged("CurrentViewModel");
              }
          }
  
          private bool isCloseModalWindow = false;
  
          public bool IsCloseModalWindow
          {
              get { return isCloseModalWindow; }
              set { isCloseModalWindow = value; OnPropertyChanged("IsCloseModalWindow"); }
          }
  
  
          public MainWindowViewModel()
          {
  
          }
  
          public ICommand LoadViewCommand =&gt; loadViewCommand ?? (loadViewCommand = new RelayCommand(showView, canShowView));
  
          private void showView(object obj)
          {
              IsCloseModalWindow = true;            
  
              CurrentViewModel = new ModalDialogViewModel(new ModalDialogModel() { Name = "New Modal Window" }, this);
          }
  
          private bool canShowView(object obj)
          {
              return true;
          }
  
          public void closeWindow()
          {
              IsCloseModalWindow = false;
          }
      }
  </code></pre>
  
  <p><strong>ModalDialog</strong></p>
  
  <pre><code>&lt;Grid MinWidth="300" Background="White"&gt;
  
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="Auto" /&gt;
              &lt;RowDefinition Height="*" /&gt;
              &lt;RowDefinition Height="Auto" /&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;Grid
              Grid.Row="0"
              MinHeight="30"
              Background="SkyBlue"&gt;
  
              &lt;Grid&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition Width="Auto" /&gt;
                      &lt;ColumnDefinition Width="*" /&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
  
                  &lt;Button                    
                      Grid.Column="1"
                      Width="40"
                      Height="25"
                      Content="X"
                      BorderThickness="0"
                      Background="Transparent"
                      Foreground="White"
                      Margin="0,0,5,0"
                      HorizontalAlignment="Right"
                      VerticalAlignment="Center"
                      Command="{Binding CancelCommand}"
                      CommandParameter="{Binding ElementName=modalDialog}"                    
                      ToolTip="Close" /&gt;
              &lt;/Grid&gt;
          &lt;/Grid&gt;
  
          &lt;Grid Grid.Row="1" Margin="15"&gt;
  
              &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition Height="Auto" /&gt;
              &lt;/Grid.RowDefinitions&gt;
  
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="Auto" /&gt;
                  &lt;ColumnDefinition Width="Auto" /&gt;
                  &lt;ColumnDefinition Width="*" /&gt;
              &lt;/Grid.ColumnDefinitions&gt;
  
              &lt;Label
                  Grid.Row="0"
                  Grid.Column="0"
                  Content="Name"
                  Style="{StaticResource commonMargin}" /&gt;
              &lt;Label
                  Grid.Row="0"
                  Grid.Column="1"
                  Content=":"
                  Style="{StaticResource commonMargin}" /&gt;
              &lt;TextBox
                  Grid.Row="0"
                  Grid.Column="2"
                  Width="100"   
                  Text="{Binding Path=Name}"
                  Style="{StaticResource commonTimerMargin}" /&gt;
  
  
          &lt;/Grid&gt;
  
          &lt;Grid
              Grid.Row="2"
              Margin="0,0,15,10"
              HorizontalAlignment="Right"&gt;
  
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="Auto" /&gt;
                  &lt;ColumnDefinition Width="Auto" /&gt;
              &lt;/Grid.ColumnDefinitions&gt;
  
              &lt;Button
                  Grid.Column="0"
                  Width="80"
                  Height="30"
                  Margin="0,0,10,0"
                  Background="White"
                  Command="{Binding CancelCommand}"
                  CommandParameter="{Binding ElementName=modalDialog}"
                  Content="CANCEL" /&gt;
              &lt;Button
                  Grid.Column="1"
                  Width="80"
                  Height="30"
                  Background="SkyBlue"
                  Command="{Binding ApplyCommand}"
                  CommandParameter="{Binding ElementName=modalDialog}"
                  Content="APPLY"
                  Foreground="White" /&gt;
  
          &lt;/Grid&gt;
      &lt;/Grid&gt;
  </code></pre>
  
  <p><strong>ModalDialogViewModel</strong></p>
  
  <pre><code>    public class ModalDialogViewModel : ViewModelBase
      {
          private ICommand cancelCommand;
          public ModalDialogModel Model { get; private set; }
          private ICloseWindow _closeWindow;
  
          public ModalDialogViewModel(ModalDialogModel modalDialogModel, ICloseWindow closeWindow)
          {
              this.Model = modalDialogModel;
              this._closeWindow = closeWindow;           
          }
  
          public ICommand CancelCommand =&gt; cancelCommand ?? (cancelCommand = new RelayCommand(CloseWindow, CanCloseWindow));        
  
          private void CloseWindow(object obj)
          {
              _closeWindow.closeWindow();
          }
  
          private bool CanCloseWindow(object obj)
          {
              return true;
          }
      }
  </code></pre>
  
  <p><strong>My Requirement is when user click the ribbon window button the modal dialog is open. The Shell window is a ribbon window. I have added HomeTab module and many other modules as separate class library.</strong>  </p>