次のように、対応するビューで単純なデータ型をマッピングするためのDataTemplateを作成しようとしています。
<DataTemplate DataType="{x:Type src:Person}">
<TextBox Text="{Binding Name}"/>
</DataTemplate>
DataTypeプロパティが認識されていないかアクセスできないことを示すコンパイラエラーが発生します。ここで何かが足りませんか?これを行うための新しい構文はありますか、それとも機能がありませんか?暗黙のテンプレートの代替ソリューションはありますか?
参考までに、ax:Key属性を使用して修飾されたDataTemplateを含む完全なコードを次に示します(これは機能します)。
<UserControl x:Class="Metro_App.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:src="clr-namespace:Metro_App"
mc:Ignorable="d"
d:DesignHeight="768" d:DesignWidth="1366">
<UserControl.Resources>
<DataTemplate x:Key="PersonTemplate">
<TextBlock Text="{Binding Name}" Foreground="White" FontSize="72"/>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="#FF0C0C0C">
<ContentControl Content="{Binding MyPerson}" ContentTemplate="{StaticResource PersonTemplate}"/>
</Grid>
</UserControl>