• silverlight mvvm viewmodel 关闭 view窗口


     

    mvvm viewmodel 关闭 view窗口

    创建DialogCloser类

    public class DialogCloser
        {
            public static readonly DependencyProperty DialogResultProperty =
                DependencyProperty.RegisterAttached(
                    "DialogResult",
                    typeof(bool?),
                    typeof(DialogCloser),
                    new PropertyMetadata(DialogResultChanged));
    
            private static void DialogResultChanged(
                DependencyObject d,
                DependencyPropertyChangedEventArgs e)
            {
                var window = d as ChildWindow;
                if (window != null)
                    window.DialogResult = e.NewValue as bool?;
            }
            public static bool? GetDialogResult(DependencyObject dp)
            {
                return (bool?)dp.GetValue(DialogResultProperty);
            }
            public static void SetDialogResult(DependencyObject target, bool? value)
            {
                target.SetValue(DialogResultProperty, value);
            }
        }
    

     xaml

    xmlns:local="clr-namespace:KTImager.BusinessApp.SLClient"	
    local:DialogCloser.DialogResult="{Binding DialogResult}">
    

    viewmodel中

            private bool? _dialogResult;
    
            public bool? DialogResult
            {
                get { return _dialogResult; }
                set
                {
                    _dialogResult = value;
                    NotifyPropertyChanged(m => m.DialogResult);
                }
            }
    
    
            public ICommand OKCommand
            {
                get
                {
                    Action act = delegate()
                    {
    
                            DialogResult = true;
                    };
                    return new RelayCommand(act);
                }
            }
    
  • 相关阅读:
    Jane Austen【简·奥斯汀】
    I Like for You to Be Still【我会一直喜欢你】
    Dialogue between Jack and Rose【jack 和 Rose的对话】
    git删除远程.idea目录
    码云初次导入项目(Idea)
    DelayQueue 订单限时支付实例
    eclipse安装spring的插件
    redis安装命令
    log4j详解
    jstree API
  • 原文地址:https://www.cnblogs.com/x-ing/p/3442257.html
Copyright © 2020-2023  润新知