wpf自定义Mvvm框架
1.DelegateCommand.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace SimpleMvvmDemo.Commands
{
class DelegateCommand : ICommand
{
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
// throw new NotImplementedException();
if(this.CanExecuteFunc==null)
{
return true;
}
this.CanExecuteFunc(parameter);
return true;
}
public void Execute(object parameter)
{
//throw new NotImplementedException();
if(this.ExecuteAction==null)
{
return;
}
this.ExecuteAction(parameter); //命令->Execute->Execute指向的方法
}
public Action<object> ExecuteAction { get; set; }
public Func<object, bool> CanExecuteFunc { get; set; }
}
}2。NotificationObject.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimpleMvvmDemo.viewmodel
{
//viewmodel的基类
class NotificationObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
if(this.PropertyChanged!=null)
{
//binding监控changed
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
} 相关推荐
88473166 2020-05-14
89427412 2020-05-06
conganguo 2020-05-06
86523296 2020-04-22
89427412 2020-02-13
conganguo 2020-01-18
86523296 2020-01-08
<ListBox Name="sideMenu" SelectedIndex="{Binding MenuSelectedIndex}" ItemsSource="{Binding MenuList}
88473166 2020-01-08
yw00yw 2020-01-03
xcolin 2020-01-03
conganguo 2019-12-21
檀木雨林 2019-12-14
conganguo 2019-12-14
xcolin 2019-12-14
yw00yw 2019-12-14
姜海强 2020-08-01
chenjinlong 2020-06-10
conganguo 2020-06-09
yw00yw 2020-05-04