My application consists of a MainWindow and two pages which get loaded into a Frame via a simple Navigation service which uses static hard-coded Uris in the ViewModelLocator. This works fine, but I am seeing some oddities with RelayCommand.
One page contains a ListBox of items and an Edit button. If I select an item in the ListBox, the CanExecute method of the EditCommand fires and enables the button (because SelectedItem is not null). When I switch to the other Page in the App, and then switch back (without doing anything) - the SelectedItem is grayed out (Selected,Inactive). No problem with that as focus is on the Menu button. The thing I can't figure out is why the Edit button is Disabled (the CanExecute of the RelayCommand did not fire when the page was re-displayed - verified with debugger) since the SelectedItem still has the correct value.
The second issue I am seeing is that after switching between the pages in my app, the RelayCommand for the Edit button is firing multiple times when I change the Selected Item in the Listbox. I can confirm via the debugger that only one instance of the ViewModel exists (the constructor only got called once.)
So far I have observed the RelayCommand firing 3 times each time a change the SelectedItem.
Can anyone explain this behaviour and offer a solution?