【发布时间】:2016-11-13 14:58:59
【问题描述】:
我正在尝试将类绑定到模板。
<UserControl
x:Class="MyApp.Controls.PaperSelectControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid>
<ScrollViewer>
<GridView x:Name="paperGrid"
ItemsSource="{x:Bind Papers}"
Width="400" Height="300" >
<GridView.ItemTemplate >
<DataTemplate x:DataType="MyApp.Model.Paper" >
<TextBlock Text="{x:Bind Color}"/>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</ScrollViewer>
</Grid>
</UserControl>
MyApp.Model.Paper 是类命名空间。
namespace MyApp.Model {
public class Paper {
public string Name { get; set; }
public string Color { get; set; }
public string Thumb { get; set; }
}
}
但我总是得到
无法解析 DataType MyApp.Model.Paper
错误
我希望有人可以帮助我解决这个问题。谢谢。
【问题讨论】:
-
x在 XAML 文件的标题中指向什么? -
我刚刚添加了完整的标题标记! @user3185569
标签: c# xaml data-binding uwp uwp-xaml