Add BaseViewModel.ps1
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
Add-Type -AssemblyName PresentationFramework
|
||||||
|
|
||||||
|
# INotifyPropertyChanged Basisklasse fuer alle ViewModels
|
||||||
|
Add-Type @"
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
|
namespace FirefoxAddinManager {
|
||||||
|
|
||||||
|
public class ObservableBase : INotifyPropertyChanged {
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
protected void OnPropertyChanged(string name) {
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RelayCommand : ICommand {
|
||||||
|
private readonly Action<object> _execute;
|
||||||
|
private readonly Func<object, bool> _canExecute;
|
||||||
|
|
||||||
|
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null) {
|
||||||
|
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
||||||
|
_canExecute = canExecute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public event EventHandler CanExecuteChanged {
|
||||||
|
add { System.Windows.Input.CommandManager.RequerySuggested += value; }
|
||||||
|
remove { System.Windows.Input.CommandManager.RequerySuggested -= value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanExecute(object parameter) => _canExecute == null || _canExecute(parameter);
|
||||||
|
public void Execute(object parameter) => _execute(parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"@ -ReferencedAssemblies PresentationFramework, PresentationCore, WindowsBase
|
||||||
Reference in New Issue
Block a user