binding command to a loaded viewmodel

You should be able to do this by giving your ContentControl a name.

<ContentControl Grid.Row="1" x:Name="MyContentControl" Content="{Binding SelectedViewModel}"/>

Then you can refer to it and its Content property that holds the view model in the command binding, e.g.:

<Fluent:Button" Command="{Binding Content.VermittlerSave, ElementName=MyContentControl}" Header="Save" LargeIcon="{iconPacks:FontAwesome Kind=SaveRegular,Width=30,Height=25}"/>

Of course, this is only applicable, if any selected view model contains the bound command.

Alternatives to binding are communicating with events, e.g. using the event aggregator pattern that most MVVM frameworks like Caliburn.Micro or Prism provide or you can have a look at Prism’s CompositeCommand approach, which allows you to create a command that other commands can attach to. You could create composite commands for your menu and dynamically attach or detach the real commands from the selected view model.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top