I am trying to implement modal dialog in the WPF Prism Desktop application.
From Prism guidance I can see that proper way should be using Interaction:
That's true it only exists in the Silverlight prism library ,
What you can do is create your own .
CS :
public class OpenPopupWindowAction : TriggerAction
{
protected override void Invoke(object parameter)
{
var popup = (ChildWindow)ServiceLocator.Current.GetInstance();
popup.Owner = PlacementTarget ?? (Window)ServiceLocator.Current.GetInstance();
popup.DialogResultCommand = PopupDailogResultCommand;
popup.Show();
}
public Window PlacementTarget
{
get { return (Window)GetValue(PlacementTargetProperty); }
set { SetValue(PlacementTargetProperty, value); }
}
public static readonly DependencyProperty PlacementTargetProperty =
DependencyProperty.Register("PlacementTarget", typeof(Window), typeof(OpenPopupWindowAction), new PropertyMetadata(null));
public ICommand PopupDailogResultCommand
{
get { return (ICommand)GetValue(PopupDailogResultCommandProperty); }
set { SetValue(PopupDailogResultCommandProperty, value); }
}
public static readonly DependencyProperty PopupDailogResultCommandProperty =
DependencyProperty.Register("PopupDailogResultCommand", typeof(ICommand), typeof(OpenPopupWindowAction), new PropertyMetadata(null));
}
XAML :
And if you need here is the Code for the DialogWindow it self .
cs:
public partial class ChildWindow : Window, IPopupDialogWindow
{
public ChildWindow()
{
InitializeComponent();
DataContext = this;
}
public new PopupDialogResult DialogResult
{
get;
set;
}
public System.Windows.Input.ICommand DialogResultCommand
{
get;
set;
}
}
xaml :
This is a child window launched from the main window