I have a view (Main View) with a toolbar and a TabContent region (PRISM). In the TabContent region I have two tabs (two views -View A, View B-) representing the same model (Contacts) in a different way.
View A contains a DataGrid with Contacts. The toolbar in the Main View contains a "Delete Button" with a DeleteCommand. I want to send with the DeleteCommand the selected contacts from View A as Command Parameters, but with the code I show below, the command parameters are null. It looks like the Main View doesn't retrieve the Selected Items from the DataGrid located in View A. How can I accomplish this?
This is the Main View:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" Background="#D6D6DC">
<ToolBar Style="{StaticResource ModuleToolBarStyle}">
<TextBlock Margin="10,0,0,0" Text="Contacts"></TextBlock>
<Button Name="addContactButton" ToolTip="Add Contact">
<Image Source="/PrismApp.Controls;component/Images/add.png"/>
</Button>
<Button Name="deleteContactsButton" ToolTip="Delete selected Contacts"
Command="{Binding DeleteContactCommand}" CommandParameter="{Binding SelectedItems, ElementName=ContactsList}">
<Image Source="/PrismApp.Controls;component/Images/delete.png"/>
</Button>
<ToggleButton Name="ViewAButton" ToolTip="View A" Command="{Binding NavigateToViewACommand}"
IsChecked="{Binding IsViewAActive}">
<Image Source="/PrismApp.Controls;component/Images/listblack.png"/>
</ToggleButton>
<ToggleButton Name="ViewBButton" ToolTip="View B" Command="{Binding NavigateToViewBCommand}"
IsChecked="{Binding IsViewBActive}">
<Image Source="/PrismApp.Controls;component/Images/tilesblack.png"/>
</ToggleButton>
</ToolBar>
</DockPanel>
<TabControl Grid.Row="1" prism:RegionManager.RegionName="ContactsViewRegion">
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Visibility" Value="Collapsed"/>
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
</Grid>
This is View A:
<Grid>
<DataGrid x:Name="ContactsList" Margin="20" AutoGenerateColumns="False" IsReadOnly="True" CanUserResizeRows="False"
CanUserResizeColumns="True" ColumnWidth="*" ItemsSource="{Binding Contacts}">
</DataGrid>
</Grid>
The view model is the same for Main View, View A and View B.