canexecute

How to use the CanExecute Method from ICommand on WPF

橙三吉。 提交于 2019-11-29 06:51:58
First to say i am at the very beginning of WPF and the MVVM Pattern. While trying some custom Commands i was wondering how to use the CanExecute Methode from the ICommand interface. In my example i have a SaveCommand which i only what to be enable when the object is saveable. The XAML Code of my Savebutton looks like this: <Button Content="Save" Command="{Binding SaveCommand, Mode=TwoWay}" /> This is the code of my save class: class Save : ICommand { public MainWindowViewModel viewModel { get; set; } public Save(MainWindowViewModel viewModel) { this.viewModel = viewModel; } public bool

What is CanExecuteChanged for?

这一生的挚爱 提交于 2019-11-29 01:25:31
Can I use CanExecuteChanged to change the "can execute" condition? Or else... "for what" its used? Tim Lloyd No you can not use it to change the can execute state. It is an event and objects which participate in the ICommand pattern can choose to listen to this event e.g. a button may use this event to know when to re-query the commands state (by calling the can execute method) to set its enabled state. In order for the can execute pattern to be useful there needs to be something that can be used to raise the event. Prism's DelegateCommand has a method you can call to manually raise this event

How to use the CanExecute Method from ICommand on WPF

孤人 提交于 2019-11-28 00:16:17
问题 First to say i am at the very beginning of WPF and the MVVM Pattern. While trying some custom Commands i was wondering how to use the CanExecute Methode from the ICommand interface. In my example i have a SaveCommand which i only what to be enable when the object is saveable. The XAML Code of my Savebutton looks like this: <Button Content="Save" Command="{Binding SaveCommand, Mode=TwoWay}" /> This is the code of my save class: class Save : ICommand { public MainWindowViewModel viewModel { get