0
내 사용자 정의 명령이 실행되지 않습니다
XAML :
<Button Command="{Binding NewServer}" Content="Save" />
뒤에 XAML의 코드 :
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
DataContext = new ServerViewModel();
}
}
ServerViewModel :
public class ServerViewModel : DependencyObject {
public ICommand NewServer;
private readonly Dispatcher _currentDispatcher;
public ServerViewModel() {
NewServer = new NewServerCommand(this);
_currentDispatcher = Dispatcher.CurrentDispatcher;
}
public void SaveNewServers() {
throw new NotImplementedException("jhbvj");
}
}
새 서버 명령 :
public class NewServerCommand : ICommand {
public event EventHandler CanExecuteChanged {
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
private readonly ServerViewModel _vm;
public NewServerCommand(ServerViewModel vm) {
_vm = vm;
}
public bool CanExecute(object parameter) {
Dispatcher _currentDispatcher = Dispatcher.CurrentDispatcher;
Action dispatchAction =() => MessageBox.Show("asd");
_currentDispatcher.BeginInvoke(dispatchAction);
return true;
}
public void Execute(object parameter) {
_vm.SaveNewServers();
}
}
CanExecute 또는 Execute가 호출되지 않습니다. 나는 무엇을 잘못 했는가?
오른쪽 ... 감사합니다. –