I am using MVVM-Light and I am working great on my relay team, I just read that I have to implement CanExecuteChanged and CanExecute . Although I can not find a good example.
Does anyone have a good example of how to implement them.
CanExecute should return False when it cannot be executed, but the button will not be simply disbale
When do I execute CanExecuteChanged ?
Someone has good examples of when to use each, my code works, but this blog says that I have to follow these points.
I'm a bit confused as I said that I thought I would just bind the Enabled property or something to the property in the ViewModel so that I can disable the button or similar control?
Any help in understanding would be greatly appreciated.
EDIT
This is what I have now ... Its working, but the button is not physically disabled, only commmand does not start, since I return false. I call CanExecuteMe in the constructor to make RaiseCanExecuteChanged work ...
This works in my constructor for my view model
this.Page2Command = new RelayCommand(() => this.GoToPage2(), () => CanExecuteMe); CanExecuteMe = false;
and here is the rest of my code, I took it from an example.
private bool _canIncrement = true; public bool CanExecuteMe { get { return _canIncrement; } set { if (_canIncrement == value) { return; } _canIncrement = value;
And here is my xaml
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="31,77,0,0" x:Name="button1" VerticalAlignment="Top" Width="75" > <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding Page2Command, Mode=OneWay}"/> </i:EventTrigger> </i:Interaction.Triggers> </Button>