我想创建一个DataTemplate用于如下用相应的视图映射为简单数据类型:如何在Metro XAML中定义隐式数据模板?
<DataTemplate DataType="{x:Type src:Person}">
<TextBox Text="{Binding Name}"/>
</DataTemplate>
我得到指示的数据类型属性无法识别或访问的编译器错误。我在这里错过了什么吗?有没有新的语法做这个或缺少的功能?是否有隐式模板的替代解决方案?
供参考,在这里与DataTemplate中的全部代码使用合格的X:Key特性(工作):
<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>
然而,有'DataTemplateKey',这是很有趣的。 –
是的。也许暗示隐含的模板正在他们的路上? – ColinE