This is a migrated thread and some comments may be shown as answers.

Basic DelegateCommand Usage Example

0 Answers 333 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Patrick asked on 01 Feb 2013, 05:47 PM
Fairly new to MVVM and learing as I go.  A little stuck on the proper usage of
Telerik.Windows.Controls DelegateCommand
.  I have the below set up, which compiles, however I am more concerned with, whether, I am using it correctly.  I have searched the Online Doc for a while now and couldn't find any examples.

Particularly, I am confused as how I would use the CanSaveAuthorization, or the underlying CanExecute, and what I would do with the object parameter that is required.

Thanks,

    

public class CreateAuthorizationViewModel : ViewModelBase
    {
        private Authorization authorization;
        private AuthorizationRepository authorizationRepository;
        private DelegateCommand saveAuthorizationCommand;
        public DelegateCommand SaveAuthorizationCommand
        {
            get
            {
                return saveAuthorizationCommand;
            }
        }
  
        public CreateAuthorizationViewModel()
        {
            InitializeCommand();
        }
        private void InitializeCommand()
        {
            saveAuthorizationCommand = new DelegateCommand(SaveAuthorization, CanSaveAuthorization);          
        }
  
        private void SaveAuthorization(object parameter)
        {
            authorizationRepository.Save();
        }
        private bool CanSaveAuthorization(object parameter)
        {
                  //I would have validation logic here
            return true;
        }
    }

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Patrick
Top achievements
Rank 2
Share this question
or