Prism PopupChildWindowAction in Desktop DLL missing

前端 未结 2 655
忘掉有多难
忘掉有多难 2021-01-14 05:08

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:



        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-14 05:51

    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
        
        
            
    
                
    
                           
                         
        
    
    
    

提交回复
热议问题