Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

How to use multiple Commands for one ViewModel

public class RelayCommand : ICommand
{
    private readonly Predicate<object> _canExecute;
    private readonly Action<object> _execute;

    public RelayCommand(Predicate<object> canExecute, Action<object> execute)
    {
        this._canExecute = canExecute;
        this._execute = execute;
    }

    public event EventHandler CanExecuteChanged
    {
        add => CommandManager.RequerySuggested += value;
        remove => CommandManager.RequerySuggested -= value;
    }

    public bool CanExecute(object parameter)
    {
        return _canExecute(parameter);
    }

    public void Execute(object parameter)
    {
        _execute(parameter);
    }
}
Comment

How to use multiple Commands for one ViewModel

public ICommand Command1 { get { return new RelayCommand(e => true, this.MethodForCommand1); } }
public ICommand Command2{ get { return new RelayCommand(e => true, this.MethodForCommand2); } }
private void MethodForCommand1(object obj){ //Type your code for Command1 }
private void MethodForCommand2(object obj){ //Type your code for Command2 }
Comment

How to use multiple Commands for one ViewModel

    <Button Content="Button 1" Command="{Binding Command1}"/>
    <Button Content="Button 2" Command="{Binding Command2}"/>
Comment

PREVIOUS NEXT
Code Example
Csharp :: block nulltarge tpl dataflow 
Csharp :: c# reduce a collection to a string 
Csharp :: how to remove black top bar in asp.net 
Csharp :: how to do Employing defensive code in the UI to ensure that the current frame is the most top level window in c# 
Csharp :: polling data source c# using threads 
Csharp :: c# boundingbox text 
Html :: html rupee symbol 
Html :: open markdown link in new tab 
Html :: html tab icon 
Html :: degree symbol html 
Html :: jqury get selected option 
Html :: free video url for testing 
Html :: bootstrap Bootstrap link 
Html :: bootstrap 5 overflow 
Html :: whatsapp html code for website 
Html :: how to add title icon in html 
Html :: box shadow svg css 
Html :: how to install jquery 
Html :: Wrap the last word of a paragraph in span tags using jQuery 
Html :: NavBar Bootstrap v4 Fix 
Html :: html favicon 
Html :: open new tab html 
Html :: onclick button href 
Html :: make a basic html page 
Html :: html implement button send email 
Html :: reactjs white space 
Html :: add favicon to website html 
Html :: This request has been blocked; the content must be served over HTTPS. 
Html :: textarea angular onfocus 
Html :: bootstrap multiselect dropdown with search stackoverflow 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =