2013-06-26 31 views

回答

1

你基本上必須創建自己的。但是,有一個例子是我之前找到的人做的。我對Prism的Interaction類進行了相當多的修改,所以我的ModalPopupAction可能與你需要的有所不同。所以相反,看看這個鏈接並下載他的例子。它有一個WPF實現!

Prism: InteractionRequest and PopupModalWindowAction for WPF applications

而如果你想知道......我的ModalPopupAction看起來像這樣(但它需要一些其他類礦井)

public class ModalPopupAction : TriggerAction<FrameworkElement> 
{ 
    public UserControl InteractionView 
    { 
     get { return (UserControl)GetValue(InteractionViewProperty); } 
     set { SetValue(InteractionViewProperty, value); } 
    } 

    // Using a DependencyProperty as the backing store for PopupDialog. This enables animation, styling, binding, etc... 
    public static readonly DependencyProperty InteractionViewProperty = 
     DependencyProperty.Register("InteractionView", typeof(UserControl), typeof(ModalPopupAction), new UIPropertyMetadata(null)); 

    protected override void Invoke(object parameter) 
    { 
     InteractionRequestedEventArgs args = parameter as InteractionRequestedEventArgs; 

     if (args == null) 
      return; 

     // create the window 
     ModalPopupDialog dialog = new ModalPopupDialog(); 
     dialog.Content = InteractionView; 

     // set the data context 
     dialog.DataContext = args.Interaction; 

     // handle finished event 
     EventHandler handler = null; 
     handler = (o, e) => 
     { 
      dialog.Close(); 
      args.Callback(); 
     }; 
     args.Interaction.Finished += handler; 

     // center window 
     DependencyObject current = AssociatedObject; 
     while (current != null) 
     { 
      if (current is Window) 
       break; 
      current = LogicalTreeHelper.GetParent(current); 
     } 
     if (current != null) 
      dialog.Owner = (current as Window); 

     dialog.ShowDialog(); 
     dialog.Content = null; 
     dialog.DataContext = null; 
     args.Interaction.Finished -= handler; 
    } 
} 
+0

非常感謝@Alan。這幫助了需要的東西! – kuhajeyan

+0

有點好奇心,想知道這是Prism團隊有意將這件事留下嗎? – kuhajeyan

+1

@kbird我認爲這是故意的,因爲這本書說「對於Silverlight,棱鏡庫提供了PopupChildWindowAction類。」我不確定他們爲什麼決定放棄WPF實施 – Alan

相關問題