mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
Refactor MainWindow with MVVM
- Add MVVM structure(BaseViewModel) - Create ViewModel for MainWindow - Refactor MainWindow.xaml to support MVVM - Move PublicAPI implementation from MainViewModel to PublicAPIInstance
This commit is contained in:
50
Wox/ViewModel/BaseViewModel.cs
Normal file
50
Wox/ViewModel/BaseViewModel.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Wox.ViewModel
|
||||
{
|
||||
public class BaseViewModel : INotifyPropertyChanged
|
||||
{
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
if (null != this.PropertyChanged)
|
||||
{
|
||||
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
}
|
||||
|
||||
public class RelayCommand : ICommand
|
||||
{
|
||||
|
||||
private Action _action;
|
||||
|
||||
public RelayCommand(Action action)
|
||||
{
|
||||
this._action = action;
|
||||
}
|
||||
|
||||
public virtual bool CanExecute(object parameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public virtual void Execute(object parameter)
|
||||
{
|
||||
if (null != this._action)
|
||||
{
|
||||
this._action();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user