如何在Metro XAML中定义隐式数据模板?
发布时间:2020-12-14 02:03:01 所属栏目:Windows 来源:网络整理
导读:我正在尝试创建一个DataTemplate,用于映射具有相应视图的简单数据类型,如下所示: DataTemplate DataType="{x:Type src:Person}" TextBox Text="{Binding Name}"//DataTemplate 我收到一个编译器错误,指示无法识别或访问DataType属性.我在这里错过了什么吗?
我正在尝试创建一个DataTemplate,用于映射具有相应视图的简单数据类型,如下所示:
<DataTemplate DataType="{x:Type src:Person}"> <TextBox Text="{Binding Name}"/> </DataTemplate> 我收到一个编译器错误,指示无法识别或访问DataType属性.我在这里错过了什么吗?是否有新的语法来执行此操作或缺少功能?是否存在隐式模板的替代解决方案? 作为参考,这里是使用x: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> 解决方法
使用WinRT,将CLR名称空间映射到XAML的语法是不同的.你应该改变你的映射:
xmlns:src="clr-namespace:Metro_App" 至 xmlns:src="using:Metro_App" 有关从Silverlight迁移到WinRT的更多信息,请参阅series of blog posts by Morten Nielsen或我写的关于creating a cross platform Silverlight / WinRT application的文章. 但是……如果你看一下API documentation for DataTemplate you will find that there is not DataType property.在WinRT中有隐式样式,但不是隐式数据模板. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- batch-file – 如何在Windows批处理中重定向FOR命令
- windows-server-2003 – Linux / Unix中的w命令是否有等效的
- 从.NET转向Win32开发
- iis – 具有相同DLL的多个网站的Azure网站内存使用情况
- 在Windows上的Ubuntu上为Bash设置$PATH的问题(Linux子系统)
- 如何使用VS在Windows 7上安装Boost
- windows – 任何人都建议一个程序一次为最终用户打印多个HT
- 相当于Win32的________在.NET中
- 适用于Windows的Netflow Collector免费版
- wix:INSTALLDIR总是以斜线结尾吗?