I have a WPF app with a Treeview and a detail page. The detail page is done via several dictionaries to handle the different layouts. Now I would like to add to the detail a edit and save button. I can bind it to the model as the data but then I have a problem how to communicate saves from the model to the viewmodel.
But if I put in the dictionary directly the name of a method that is in the code behind of the view I get an error at runtime.
This is the TreeView in the MasterDetailPage.xaml:
<TreeView
x:Name="TreeView"
Grid.Row="1"
ItemTemplate="{StaticResource PAZHTemplate}"
ItemsSource="{Binding Patients}"
SelectedItemChanged="select_SelectedItemChanged"
TreeViewItem.Expanded="ExpandItem" />
This is the details element:
<ContentControl
Grid.Column="2"
Margin="{StaticResource XSmallLeftTopMargin}"
Content="{Binding Selected}"
ContentTemplateSelector="{StaticResource ContentTemplateSelector}" />
Here we go with the Selector:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="TitoDoc\TPazDictionary.xaml" />
<ResourceDictionary Source="TitoDoc\TAppDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
<templateSelectors:TreeViewDataContentTemplateSelector
x:Key="ContentTemplateSelector"
APPTemplate="{StaticResource APPContentTemplate}"
APRTemplate="{StaticResource APRContentTemplate}"/>
And here the TPazDictionary.xaml
<Button
x:Name="Save"
Grid.Column="1"
Content=""
Command="{Binding CmdSaveSwitch, Mode=OneWay}"
ContentTemplate="{StaticResource IconFilterButton}"
DockPanel.Dock="Right"
ToolTipService.ToolTip="Save"
Visibility="{Binding IsVisible}" />
<Button
x:Name="LockUnlock"
Grid.Column="2"
Command="{Binding CmdEditSwitch, Mode=OneWay}"
Content="{Binding Icon}"
ContentTemplate="{StaticResource IconFilterButton}"
DockPanel.Dock="Right"
ToolTipService.ToolTip="Edit" />
</Grid>
<Grid Margin="0,6,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="40" />
<ColumnDefinition Width="*" MinWidth="40" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="12" />
<RowDefinition Height="Auto" MinHeight="12" />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Padding="2"
Style="{DynamicResource ContentLabel}"
Text="Cognome" />
<TextBox
Grid.Row="1"
Grid.Column="0"
IsReadOnly="{Binding IsReadOnly}"
Text="{Binding Paz.Cognome}" />
<TextBlock
Grid.Row="0"
Grid.Column="1"
Style="{DynamicResource ContentLabel}"
Text="Nome" />
<TextBlock
Grid.Row="1"
Grid.Column="1"
Style="{DynamicResource ContentData}"
Text="{Binding Paz.Nome}" />
</Grid>
</StackPanel>
</ScrollViewer>
This is the binding with the model:
Command="{Binding CmdSaveSwitch, Mode=OneWay}"
but if I put
Command="Save_Click"
I get the error even if in MasterDetailPage.xaml.cs the method is defined:
private void Save_Click(object sender, System.Windows.RoutedEventArgs e)