zoukankan      html  css  js  c++  java
  • WPF PrismDialog PopupWindowAction使用MetroWindow

    本示例必须在prism5.0版本以上

    PopupWindowAction如何使用MetroWindow?

     

    public class Window1ViewModel:BindableBase,IInteractionRequestAware
        {
            #region Properties
            private string str;
    
            public string Str
            {
                get { return str; }
                set { SetProperty(ref str, value); }
            }
    
            #endregion
    
            /// <summary>
            /// Cancel
            /// </summary>
            private DelegateCommand<Window> clickCommand;
    
            public DelegateCommand<Window> ClickCommand
            {
                get
                {
                    if (clickCommand == null)
                        clickCommand = new DelegateCommand<Window>(Click);
                    return clickCommand;
                }
            }
    
            private INotification  notification;
    
            public INotification Notification
            {
                get { return notification; }
                set { SetProperty(ref notification,value); }
            }
    
            public Action FinishInteraction { get; set; }
    
            private void Click(Window window)
            {
                var _notification = (Window1DialogModel)Notification;
                _notification.Str = this.str;
                _notification.Confirmed = true;
                FinishInteraction?.Invoke();
            }
        }
    Window1ViewModel
      public class Window1DialogModel : IConfirmation
        {
            public string Str { get; set; }
    
            //Interface Content
            public bool Confirmed { get ; set ; }
            public string Title { get ; set ; }
            public object Content { get; set; }
        }
    Window1DialogModel
    <UserControl x:Class="Pfu.ScanSnap.Home.UI.SshUIUserData.Views.Window1"
                               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                               xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
                               xmlns:MetroControls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                               xmlns:prism="http://www.codeplex.com/prism"
                               xmlns:prop="clr-namespace:Pfu.ScanSnap.Home.UI.SshUIUserData.Properties"
                               xmlns:util ="clr-namespace:Pfu.ScanSnap.Home.UI.SshUIUserData.Util"
                               prism:ViewModelLocator.AutoWireViewModel="True"
                               mc:Ignorable="d"
                               BorderBrush="#FF666666"
                               BorderThickness="1"
                               Width="500" Height="300">
        <UserControl.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary  Source="/SshUIUserData;component/Styles/ResourceDictionary.xaml"/>
                    <ResourceDictionary  Source="/SshUIUserData;component/Styles/BaseStyles.xaml" />
    
                    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.Buttons.xaml" />
                    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </UserControl.Resources>
    
        <Grid>
            <StackPanel Orientation="Vertical" VerticalAlignment="Center">
                <TextBox Text="{Binding Str}"/>
                <Button Content="Click" Command="{Binding ClickCommand}" CommandParameter="{Binding ElementName=_window1_}"/>
            </StackPanel>
        </Grid>
    </UserControl>
    Window1

    // 核心块

     public class MetroPopupWindowAction:PopupWindowAction
        {
            protected override Window CreateWindow()
            {
                return new MessageDialogWindow();
            }
        }
    MetroPopupWindowAction
    <!--Window1 Dialog-->
            <prism:InteractionRequestTrigger SourceObject="{Binding Window1DialogRequest}">
                <util:MetroPopupWindowAction IsModal="True" CenterOverAssociatedObject="True">
                    <util:MetroPopupWindowAction.WindowContent>                   
                        <local:Window1/>
                    </util:MetroPopupWindowAction.WindowContent>
                </util:MetroPopupWindowAction>
            </prism:InteractionRequestTrigger>
    View Code
    private void OK()
            {
                Window1DialogRequest.Raise(new Window1DialogModel { Str = $"6666", Title = "Window1" }, _ =>
                {
                    MessageBox.Show(_.Str);
                });
            }
            #endregion
    
            #region NotificationRequest
            public InteractionRequest<Window1DialogModel> Window1DialogRequest { get; set; }
            #endregion
    
            public ExportMainWindowViewModel()
            {
                Window1DialogRequest = new InteractionRequest<Window1DialogModel>();
            }
    TestWindowViewModel
  • 相关阅读:
    无符合条件的记录,SUM函数返回NULL。返回0而不是Null
    Java中的堆栈,队列,链表
    Java集合类的问题
    2014.7.30日结
    我的CSS之路1
    2014.7.27-7.28日结
    LeetCode解题源代码链接集锦一
    2014.7.23日结
    C++之数组声明与初始化
    系统结构之指令
  • 原文地址:https://www.cnblogs.com/ilison/p/10655359.html
Copyright © 2011-2022 走看看