I want to create a user interface for the inventory management wizard. Corresponding line in xaml:
<ContentPresenter Content="{Binding Current}" ContentTemplateSelector="{StaticResource inventorySelector}"/>
Current is the currently active view model, one of the available: InventoriesViewModel, GroupViewModel, NewArticlesViewModel, ResultViewModel. DataTemplateSelector I am defined as such:
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using Centron.WPF.WarehousingExtension.InventoryModule.ViewModels.WizardViewModels;
namespace Centron.WPF.WarehousingExtension.InventoryModule.UI.DataTemplateSelectors
{
public class InventoryDatatemplateSelector : DataTemplateSelector
{
public DataTemplate AvailableDatatype { get; set; }
public DataTemplate GroupsDatatype { get; set; }
public DataTemplate NewDatatype { get; set; }
public DataTemplate ResultDatatype { get; set; }
public InventoryDatatemplateSelector()
{
Debug.WriteLine("");
}
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item is AvailableInventoriesViewModel)
return AvailableDatatype;
else if (item is GroupsViewModel)
return GroupsDatatype;
else if (item is NewArticlesViewModel)
return NewDatatype;
else return ResultDatatype;
}
}
}
Then I instantiate the DataTemplates and selector as follows:
<base:InventoryViewBase.Resources>
<DataTemplate DataType="viewModels:AvailableInventoriesViewModel" x:Key="availableInventoriesDatatype">
<controls:AvailableInventoriesView />
</DataTemplate>
<DataTemplate DataType="viewModels:GroupsViewModel" x:Key="groupsDatatype">
<controls:GroupsView />
</DataTemplate>
<DataTemplate DataType="viewModels:NewArticlesViewModel" x:Key="newArticlesDatatype">
<controls:NewArticlesView />
</DataTemplate>
<DataTemplate DataType="viewModels:ResultViewModel" x:Key="resultDatatype">
<controls:ResultView/>
</DataTemplate>
<selector:InventoryDatatemplateSelector
x:Key="inventorySelector"
AvailableDatatype="{StaticResource availableInventoriesDatatype}"
GroupsDatatype="{StaticResource groupsDatatype}"
NewDatatype="{StaticResource newArticlesDatatype}"
ResultDatatype="{StaticResource resultDatatype}"/>
</base:InventoryViewBase.Resources>
I set a breakpoint in the constructor of my InventoryDatatemplateSelector and can go through it, but in the next debugging step, apparently when it tries to set the first property of this selector instance, I immediately get an exception from the internal exception:
\ "availableInventoriesDatatype \". .
, , ?