WPF PrismDialog PopupWindowAction使用MetroWindow

原文: 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

 

posted on 2019-04-05 00:16 NET未来之路 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/10657679.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值