加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

WPF PrismDialog PopupWindowAction使用MetroWindow

发布时间:2020-12-14 04:34:58 所属栏目:大数据 来源:网络整理
导读:原文: WPF PrismDialog PopupWindowAction使用MetroWindow 本示例必须在prism5.0版本以上 PopupWindowAction如何使用MetroWindow? ? public class Window1ViewModel:BindableBase,IInteractionRequestAware { #region Properties private string str; publi
原文: 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读