TemplateColumn<TModel> supports a resource-key constructor so model/viewmodel code can reference XAML templates by key.
new TemplateColumn<Country>(
"Region",
"RegionCell",
"RegionEditCell")
The sample project uses this pattern in multiple view models (CountriesPageViewModel, FilesPageViewModel, WikipediaPageViewModel).
<TreeDataGrid.Resources>
<DataTemplate x:Key="RegionCell" DataType="m:Country">
<TextBlock Text="{Binding Region}"/>
</DataTemplate>
<DataTemplate x:Key="RegionEditCell" DataType="m:Country">
<ComboBox ItemsSource="{x:Static m:Countries.Regions}"
SelectedItem="{Binding Region}"/>
</DataTemplate>
</TreeDataGrid.Resources>
TemplateColumn<TModel> resolves keys with anchor.FindResource(key) when template cells are realized.
Key behavior:
KeyNotFoundExceptionKeyNotFoundExceptionDataType and stable bindings in each templateKeyNotFoundException for template key
Cause: key does not exist or is not visible in lookup scope.
Fix: place template in TreeDataGrid.Resources, parent resources, or Application.Resources.
Cell never enters editing
Cause: no editing template key was provided; TemplateCell.CanEdit is false.
Fix: pass editing template key (or direct editing template instance) to TemplateColumn.
Edit starts but fails with KeyNotFoundException
Cause: editing key was provided, but no matching keyed DataTemplate exists in
resource scope.
Fix: define the editing template key in scope or remove editing-key usage.