0

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 Executed. (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?

Community
  • 1
  • 1
Tar
  • 8,529
  • 9
  • 56
  • 127
  • Can you expand your post with an example? It's hard to understand what you exactly need. – nvoigt Jan 15 '15 at 15:09
  • @nvoigt - I expanded the question – Tar Jan 15 '15 at 15:31
  • If your window knows nothing about the user control, the user control could feature a bindable bool that indicates it's busy. Your window can bind to it and react accordingly. – nvoigt Jan 15 '15 at 15:37
  • @nvoigt, there's no way to bubble up the information like with routed events, but using the commands mechanism? – Tar Jan 15 '15 at 15:39
  • I'm not sure what you mean. Yes, you can use routed events. For example raise one. You can raise one whenever you feel like it, I'm not sure how this would conflict with your commands? – nvoigt Jan 15 '15 at 15:43
  • I can't raise routed event from a command (the command currently implements an `ICommand`, so it does the work of "fueling" by itself - the functionality is located within that command), since it's not a `UIElement`. I can pass the `UIElement` object (i.e. the `CarUserControl` object) to it somehow, but that would result in spaghetti-code... – Tar Jan 15 '15 at 15:45
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/68892/discussion-between-tal-and-nvoigt). – Tar Jan 15 '15 at 15:56

0 Answers0