zoukankan      html  css  js  c++  java
  • wpf自定义Mvvm框架

    1.DelegateCommand.cs

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 using System.Windows.Input;
     7 
     8 namespace SimpleMvvmDemo.Commands
     9 {
    10     class DelegateCommand : ICommand
    11     {
    12 
    13         public event EventHandler CanExecuteChanged;
    14 
    15         public bool CanExecute(object parameter)
    16         {
    17             // throw new NotImplementedException();
    18             if(this.CanExecuteFunc==null)
    19             {
    20                 return true;
    21             }
    22             this.CanExecuteFunc(parameter);
    23             return true;
    24         }
    25 
    26         public void Execute(object parameter)
    27         {
    28             //throw new NotImplementedException();
    29             if(this.ExecuteAction==null)
    30             {
    31                 return;
    32             }
    33             this.ExecuteAction(parameter); //命令->Execute->Execute指向的方法
    34         }
    35 
    36         public Action<object> ExecuteAction { get; set; }
    37         public Func<object, bool> CanExecuteFunc { get; set; }
    38     }
    39 }

    2。NotificationObject.cs

     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Linq;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 
     8 namespace SimpleMvvmDemo.viewmodel
     9 {
    10     //viewmodel的基类
    11     class NotificationObject : INotifyPropertyChanged 
    12     {
    13         public event PropertyChangedEventHandler PropertyChanged;
    14         public void RaisePropertyChanged(string propertyName)
    15         {
    16             if(this.PropertyChanged!=null)
    17             {
    18                 //binding监控changed
    19                 this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); 
    20             }
    21         }
    22     }
    23 }
  • 相关阅读:
    Java中四个作用域的可见范围
    java构造方法前加void有什么作用
    css3渐变
    日历插件
    三级联动地点
    js返回上一级代码和刷新页面代码
    css3滚动条
    如何写评价“星星”有半个情况的,如3.5,这样写好调数据
    原生态js单个点击展开收缩和jQuery的写法
    推荐大家使用的CSS书写规范、顺序
  • 原文地址:https://www.cnblogs.com/sclu/p/12177491.html
Copyright © 2011-2022 走看看