Basic DelegateCommand Usage Example

1 posts, 0 answers
  1. Patrick
    Patrick avatar
    42 posts
    Member since:
    Jul 2012

    Posted 01 Feb 2013 Link to this post

    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;
            }
        }
Back to Top