Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to create multiple commands in a viewmodel ( WPF, MVVM Pattern )

$
0
0

My project has a viewmodel class in which I have inherited RelayCommand and ICommand. 

A Command called ExecuteCommand is created in this view model as shown below and is working fine.

public class LoginWindowViewModel:WorkSpaceViewModel
    {  
        RelayCommand _executecommand;        
        public ICommand ExecuteCommand
        {
            get
            {
                if (_executecommand == null)
                {
                   _executecommand = new RelayCommand(param => Execute(),param => CanExecute());
                }
                return _executecommand;
            }
        }        

        public virtual void Execute()
        {            
            MainWindow window = new MainWindow();
            window.Show();            
        }

        public virtual bool CanExecute()
        {
            return true;
        }
    }

My question is, how can I create another command in the same view model and how to use it.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>