Вот пример, показывающий, как работает метод can-execute. Кнопка подтверждения становится активной, если в поле ввода строки подключения есть текст. Это не совсем похоже на ваш код, но вы ссылаетесь на список, которого я не вижу в вашем XAML.
MainWindow.xaml (ничего в коде позади)
<Window x:Class="FrameworkCanExecuteExample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FrameworkCanExecuteExample"
mc:Ignorable="d"
Title="MainWindow"
Width="300"
Height="100">
<Window.DataContext>
<local:MainViewModel />
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="Connection string:" />
<TextBox Grid.Column="1" Text="{Binding Path=ConnectionString, UpdateSourceTrigger=PropertyChanged}" />
<Button Grid.Row="1" Grid.ColumnSpan="2" Content="Confirm" Command="{Binding BtnConfirm}" />
</Grid>
</Window>
MainViewModel. cs
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
namespace FrameworkCanExecuteExample
{
public class MainViewModel : INotifyPropertyChanged
{
private string connectionString;
public event PropertyChangedEventHandler PropertyChanged;
public MainViewModel()
{
BtnConfirm = new RelayCommand(Confirm, CanConfirm);
}
public string ConnectionString
{
get => connectionString;
set
{
connectionString = value;
OnPropertyChanged();
}
}
public ICommand BtnConfirm { get; }
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void Confirm(object parameter)
{
}
private bool CanConfirm(object parameter)
{
return !string.IsNullOrWhiteSpace(connectionString);
}
}
}
RelayCommand.cs
using System;
using System.Windows.Input;
namespace FrameworkCanExecuteExample
{
public class RelayCommand : ICommand
{
private Action<object> execute;
private Func<object, bool> canExecute;
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
this.execute = execute;
this.canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return canExecute == null || canExecute(parameter);
}
public void Execute(object parameter)
{
execute(parameter);
}
}
}