rob*_*zhu 5 xaml datatemplate windows-8 windows-runtime
我正在尝试创建一个DataTemplate,用于映射具有相应视图的简单数据类型,如下所示:
<DataTemplate DataType="{x:Type src:Person}">
<TextBox Text="{Binding Name}"/>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
我收到一个编译器错误,指示无法识别或访问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>
Run Code Online (Sandbox Code Playgroud)
使用WinRT,将CLR名称空间映射到XAML的语法是不同的.你应该改变你的映射:
xmlns:src="clr-namespace:Metro_App"
Run Code Online (Sandbox Code Playgroud)
至
xmlns:src="using:Metro_App"
Run Code Online (Sandbox Code Playgroud)
有关从Silverlight迁移到WinRT的更多信息,请参阅Morten Nielsen撰写的一系列博客文章,或者我撰写的关于创建跨平台Silverlight/WinRT应用程序的文章.
但是......如果查看DataTemplate的API文档,您会发现没有DataType属性.在WinRT中有隐式样式,但不是隐式数据模板.
| 归档时间: |
|
| 查看次数: |
4643 次 |
| 最近记录: |