Search code examples
c#wpfcommandmodern-ui

Two commands to one button


I'd like to bind two actions to a ModernUI link: when clicked, it should a) trigger a RelayCommand and b) navigate. I have googled and read but could not find a solution. So far, I only made it to either bind or navigate, but not both..

E.g. in the sample ModernUI application, Navigation takes place like this:

                <Button Content="introduction" Margin="0,0,4,0"
                        Command="mui:LinkCommands.NavigateLink"
                        CommandParameter="/Pages/Introduction.xaml"/>

But then the Command property is already used, so how could I attach my second Command to it?

                <Button Content="introduction"
                        Command="{Binding MyCommand}">

I've also tried using a ListBox, where I can use the SelectedItem property, but this one has no Command property.

I'd be thankful for a hint!


Solution

  • This CodeProject site shows an implementation of a list of Commands that presents itself to be one command. That way, calling one would call the others.

    In fact, the class just implements ICommand and an ObservableCollection of Commands that get executed when called.

    That seems a proper solution for your problem.