桌面DLL中缺少Prism PopupChildWindowAction [英] Prism PopupChildWindowAction in Desktop DLL missing

查看:66
本文介绍了桌面DLL中缺少Prism PopupChildWindowAction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在WPF Prism Desktop应用程序中实现模式对话框.

I am trying to implement modal dialog in the WPF Prism Desktop application.

从Prism指南中,我可以看到应该使用交互"的正确方法:

From Prism guidance I can see that proper way should be using Interaction:

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

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

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

但是对于台式机来说,Microsoft.Practices.Prism.Interactivity.DLL库中没有PopupChildWindowAction,只有Silverlight吗?

But PopupChildWindowAction is not available in the Microsoft.Practices.Prism.Interactivity.DLL library for Desktop, only Silverlight?

我可以在WPF(Prism)中用谷歌搜索模态对话框的许多不同实现,但是只是想知道为什么Prism Desktop DLL中缺少此功能,而Silverlight DLL中提供了此功能? 我可以使用Interaction Service,但建议使用Interaction Request作为MVVM应用程序更合适的方法.

I could google for many different implementations of the Modal Dialog in WPF (Prism), but just wondering why this feature is missing from Prism Desktop DLL and is available in Silverlight DLL? I could use Interaction Service but Interaction Request is suggested as more appropriate approach for MVVM application.

推荐答案

是的,它仅存在于Silverlight棱镜库

That's true it only exists in the Silverlight prism library ,

您可以做的就是创建自己的.

What you can do is create your own .

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的代码.

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:

  <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>

这篇关于桌面DLL中缺少Prism PopupChildWindowAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆