The scenario is this:
I have an application developed in WPF, MVVM, Prism 6.3.0. This app considers
- Shell.xaml (the shell)
- UserControl1.xaml (inside a module, independient Class Library)
When I click on the Button defined in the Shell, I expect the command being executed and the condition defined in CanExecute be verified. But, this command is defined into the ViewModel class that's the view model of the module (in this application will be more than one module, loaded as Prism implements this traditionally).
To be called, I tried to define a localviewmodel into the resources collection of the Shell. This triggers the command, but doesn't triggers the condition CanExecute.
If I put the XAML code defined in the user control inside the module, (in other words, If I code a simple app with no use of Content region manager) a single-page XAML app, the command verifies the CanExecute without a problem. My best guess is a problem of binding the command defined in the module viewmodel, into a button in the Shell. Having read a lot about it, I just don't get the right way of declaring the binding.
Here's an example:
<Telerik:RadRibbonView x:Name="BarraHerramientas" Grid.Row="0"
DockPanel.Dock="Top"
ContentHeight="130"
Height="160"
Template="{DynamicResource RadRibbonViewStyle}"
MinimizeButtonVisibility="Visible"
HelpButtonVisibility="Visible" Background="Red">
<Telerik:RadRibbonTab Header="1"
Style="{DynamicResource RadRibbonTabStyle}"
IsSelected="True"
TabIndex="0">
<Telerik:RadRibbonGroup Header="RibbonGroup1"
DialogLauncherVisibility="Visible">
<Telerik:RadRibbonButton CollapseToMedium="Never"
CollapseToSmall="WhenGroupIsMedium"
IsAutoSize="True"
LargeImage="Agregar.png"
Size="Large"
SmallImage="Agregar_16x16.png"
Text="Add..."
Command="{Binding AddRecordCommand, Source={StaticResource LocalViewModel}}"
CommandTarget="{Binding ElementName=MyRecords}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" "
Telerik:ScreenTip.Description="..." />
</Telerik:RadRibbonGroup>
</Telerik:RadRibbonTab>
</Telerik:RadRibbonView>
Where MyRecords is the name of the GridView that holds the data, and LocalViewModel is the key of the instance of the ViewModel defined in the loaded module. So, there's two instances in a point of time of LocalViewModel, the one defined as a resource in Shell.xaml, and the one defined into the loaded Module that holds the "MyRecords" GridView.
Using a one-page example, this works flawless, of course. And because I need to write a few modules, each one defines it's own ViewModel, or more than one. So, thats because I need to use commands defined into the different module's viewmodels, from the Shell. If I declare each ViewModel in the shell (a LOT of data coming in) probably will be a performance issue.
So, how can I call a command (from the shell) that is defined in a ViewModel as a resource in a module being loaded "on demand"?
Thanks everyone.