TL/DR:
How can I notify the containing Window
that a certain UserControl
it contains invoked an ICommand
/RelayCommand
/DelegateCommand
?
I want to respond the CanExecuteChanged
events in the Window
.
Expansion:
The UserControl
:
<UserControl x:Class="CarProject.CarUserControl" ... >
<!-- lots of stuff here... -->
<Button Name="FuelCar" Command="{Binding FuelCarCommand}"
CommandParameter="{Binding FuelType}" >
Start fueling the car...
</Button>
<!-- lots of stuff here... -->
</UserControl>
The Window
:
<Window ...
xmlns:carProject="clr-namespace:CarUserControl;assembly=CarUserControl"
...
>
<!-- lots of stuff here... -->
<carProject:CarUserControl Name="TheCar"/>
<!-- lots of stuff here... -->
</Window>
Whenever the button FuelCar
is clicked, a custom command, FuelCarCommand
is Execute
d. (what should be the right type for FuelCarCommand
? simple ICommand
implementation? a RelayCommand
subtype or a DelegateCommand
? or maybe simply Routed Events
and that's it... ?).
That command does some business-logic stuff, and while it works (it takes time to fuel the car), other controls in the CarUserControl
are disabled.
But I also need the Window
to disable some controls that are not directly related to CarUserControl
(e.g. FuelStationNumberOne
should be disabled since it's occupied by the CarUserControl
).
What is the right way to accomplish that? do commands are the right mean here?