I'm unable to bind the <ContentControl Content={Binding Type}/>
to the local resources <DataTemplate>
when binding my custom property on my POCO class called Type
(I'm hoping it's not down to the bad choice of naming).
ReportItemModel
public class ReportItemModel
{
public ReportItemModel(string name, ReportItemType itemType, Type type)
{
Name = name;
ItemType = itemType;
Type = type;
}
public string Name { get; }
public ReportItemType ItemType { get; }
public Type Type { get; }
}
XAML
<ContentControl Content="{Binding Type}" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3">
<ContentControl.Resources>
<DataTemplate DataType="{x:Type moduleTypes:ReportModule}">
<Label>Test</Label>
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
The Type
property is (as you've probably guessed) a System.Type
and the output within my WPF application is always the output of ToString()
which I'm guessing is down to a failed match of my <DataTemplate>
. If I change the ContentControl
to Content={Binding}
and set the <DataTemplate>
to accept the data type of the POCO class ReportItemModel
it works as intended. The only difference I can see is that ReportItemModel
has been instantiated where as the Type
property has not.