Files
firefox-addin-manager/MVVM/ViewModels/BaseViewModel.ps1
T
2026-06-10 21:57:54 +02:00

37 lines
1.3 KiB
PowerShell

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