【问题标题】:Prism PopupChildWindowAction in Desktop DLL missing缺少桌面 DLL 中的 Prism PopupChildWindowAction
【发布时间】:2013-09-06 22:01:05
【问题描述】:

我正在尝试在 WPF Prism 桌面应用程序中实现模式对话框。

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

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

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

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

但是PopupChildWindowAction 在桌面的 Microsoft.Practices.Prism.Interactivity.DLL 库中不可用,只有 Silverlight?

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

【问题讨论】:

    标签: c# wpf mvvm prism prism-4


    【解决方案1】:

    没错,它只存在于 Silverlight prism 库中,

    你可以做的是创建你自己的。

    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:

    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 中已经存在类似的东西。我不明白为什么它只在 Silverlight DLL 中可用?
    • 我看不到 :),除了实​​现过于复杂并依赖于 2 个非常具体的通知对象外,你想要的只是一个带有消息的弹出窗口..
    【解决方案2】:
    猜你喜欢
    • 2016-12-05
    • 1970-01-01
    • 2013-06-21
    • 2019-12-16
    • 2011-04-15
    • 2020-09-01
    • 2014-08-31
    • 2010-09-18
    • 1970-01-01
    相关资源
    最近更新 更多