public class PrpertiesWindowViewModel : BaseViewModel { private string name; public string Name { get { return name; } set { name = value; OnPropertyChanged("Name"); OnPropertyChanged("IsEnabled"); } } private string address; public string Address { get { return address; } set { address = value; OnPropertyChanged("Address"); OnPropertyChanged("IsEnabled"); } } private readonly ICommand buttonCommand; public ICommand ButtonCommand { get { return this.buttonCommand; } } public List Rooms { get; set; } public PrpertiesWindowViewModel() { Rooms = new List(); FillList(); this.buttonCommand = new RelayCommand(CmdExec, CanCmdExec); } private void CmdExec(object parameter) { // Code to save data here. MessageBox.Show(" clicked "); } private bool CanCmdExec(object obj) => true; public bool IsEnabled { get { return !(((string.IsNullOrEmpty(this.Name)) || (string.IsNullOrEmpty(this.Address)) )); } } private void FillList() { for (int i = 1; i < 50; i++) { Rooms.Add(i); } } } public class RelayCommand : ICommand { private readonly Predicate _canExecute; private readonly Action _action; public RelayCommand(Action action, Predicate canExecute) { _action = action; _canExecute = canExecute; } public void Execute(object o) => _action(o); public bool CanExecute(object o) => _canExecute == null ? true : _canExecute(o); public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } }