2013-09-03 4 views
3

WPF 프리즘 데스크톱 응용 프로그램에서 모달 대화 상자를 구현하려고합니다.프리즘 PopupChildWindowAction이없는 데스크톱 DLL

<i:Interaction.Triggers> 
    <prism:InteractionRequestTrigger 
      SourceObject="{Binding ConfirmCancelInteractionRequest}"> 

     <prism:PopupChildWindowAction 
        ContentTemplate="{StaticResource ConfirmWindowTemplate}"/> 

    </prism:InteractionRequestTrigger> 
</i:Interaction.Triggers> 

그러나 PopupChildWindowAction은 데스크톱에 대한 Microsoft.Practices.Prism.Interactivity.DLL 라이브러리 만 실버 사용할 수 없습니다 :

프리즘지도에서 나는 적절한 방법이 상호 작용을 사용하는 것을 볼 수 있습니까?

WPF (프리즘)의 모달 대화 상자에 대한 여러 가지 구현에 대해 google을 할 수 있지만이 기능이 프리즘 데스크톱 DLL에없는 이유와 Silverlight DLL에서 사용할 수 있는지 궁금하십니까? 상호 작용 서비스를 사용할 수 있지만 MVVM 응용 프로그램에 더 적합한 방법으로 상호 작용 요청이 제안되었습니다. 그것은 단지 실버 프리즘 라이브러리에있는 사실

답변

6

,

은 당신이 할 수있는 것은 당신의 자신을 만드는 것입니다.

CS :

public class OpenPopupWindowAction : TriggerAction<FrameworkElement> 
{  
    protected override void Invoke(object parameter) 
    {   
     var popup = (ChildWindow)ServiceLocator.Current.GetInstance<IPopupDialogWindow>(); 
     popup.Owner = PlacementTarget ?? (Window)ServiceLocator.Current.GetInstance<IShell>(); 

     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 :

<i:EventTrigger SourceObject="{Binding}" EventName="NavigatedFrom"> 
     <popup:OpenPopupWindowAction PopupDailogResultCommand="{Binding OnNavigationConfirmed}"/> 
    </i:EventTrigger> 

그리고 당신은 DialogWindow의 그것 자체에 대한 코드를 여기에서 필요로하는 경우.

CS :

XAML
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; 
    } 
} 

:

<Window x:Class="Utils.ActionPopupWindow.ChildWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="300" Width="400" WindowStartupLocation="CenterOwner" 
    xmlns:popup="clr-namespace:Utils.ActionPopupWindow" 
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
    x:Name="popUpWindow" 
    > 

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*"/> 
     <RowDefinition Height="30"/> 
    </Grid.RowDefinitions> 
    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="30"> 
     This is a child window <LineBreak/> launched from the <LineBreak/>main window 
    </TextBlock> 
    <StackPanel Grid.Row="1" Background="#FFA6A6A6"> 
     <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> 

      <Button Content="Ok" 
        MinWidth="100" 
        Command="{Binding DialogResultCommand}" 
        CommandParameter="{x:Static popup:PopupDialogResult.OK}" 
        > 
       <i:Interaction.Triggers> 
         <i:EventTrigger EventName="Click"> 
         <ei:CallMethodAction MethodName="Close" TargetObject="{Binding ElementName=popUpWindow}"/> 
         </i:EventTrigger> 
        </i:Interaction.Triggers> 
      </Button> 

      <Button Content="Cancel" 
        MinWidth="100" 
        Command="{Binding DialogResultCommand}" 
        CommandParameter="{x:Static popup:PopupDialogResult.Cancel}" 
        > 
       <i:Interaction.Triggers> 
        <i:EventTrigger EventName="Click"> 
         <ei:CallMethodAction MethodName="Close" TargetObject="{Binding ElementName=popUpWindow}"/> 
        </i:EventTrigger> 
       </i:Interaction.Triggers> 
      </Button>   
     </StackPanel>    
    </StackPanel> 

</Grid> 
여기

+0

감사합니다, 나는 비슷한 일을 계획했지만, 바퀴를 재발견하고 싶지 않았고, 뭔가를 기대하고 있었다. 이 같은 이미 데스크톱 DLL에 존재합니다. 이유는 Silverlight DLL에서만 사용할 수있는 이유가 표시되지 않습니까? – user007

+0

내가 볼 수있는 것은 아닙니다 :) 거기에 구현은 2 개의 매우 구체적인 알림 개체에 대한 복잡한 작업과 릴레이 작업인데 메시지가있는 팝업이 없습니다. –