using System; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Input; namespace WpfApp006 { public class MainWindowVM : INotifyPropertyChanged { public ICommand CreateNewTextBoxCommand { get => new HelperCommand((state) => { Num = DateTime.Now.ToLongTimeString(); RaisePropertyChanged(nameof(Num)); }); } public string Num { get; set; } public event PropertyChangedEventHandler PropertyChanged; private void RaisePropertyChanged([CallerMemberName] string propName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName)); } public class HelperCommand : ICommand { private readonly Action _execute; private readonly Predicate _canExecute; public HelperCommand(Action execute) : this(execute, canExecute: null) { } public HelperCommand(Action execute, Predicate canExecute) { if (execute == null) throw new ArgumentNullException("execute"); this._execute = execute; this._canExecute = canExecute; } public event EventHandler CanExecuteChanged; public bool CanExecute(object parameter) => this._canExecute == null ? true : this._canExecute(parameter); public void Execute(object parameter) => this._execute(parameter); public void RaiseCanExecuteChanged() => this.CanExecuteChanged?.Invoke(this, EventArgs.Empty); } }