c# - 在 UWP 中显示一个简单的客户列表
问题描述
所以我目前从这里复制/粘贴一些代码:https ://docs.microsoft.com/en-us/windows/uwp/get-started/display-customers-in-list-learning-track
代码如下所示:
xaml:
<ListView ItemsSource="{x:Bind Customers}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:Customer">
<TextBlock Text="{x:Bind Name}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
关于x:Bind Customers
:它似乎不会像错误的那样自动完成。
关于x:DataType="local:Customer"
:我收到错误消息The name "Customer" does not exist in the namespace "using:helloUWP"
cs:
namespace helloUWP
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
///
public class Customer
{
public string Name { get; set; }
}
public sealed partial class MainPage : Page
{
public ObservableCollection<Customer> Customers { get; }
= new ObservableCollection<Customer>();
public MainPage()
{
this.InitializeComponent();
this.Customers.Add(new Customer() { Name = "Name1" });
}
}
}
我无法建造它。我错过了什么或做错了什么?
解决方案
要在 XAML 中使用自定义类,首先必须在根元素中声明适当的命名空间,例如 for Page
:
<Page ... xmlns:models="TheNamespaceWhereCustomerIs">
然后使用:
x:DataType="models:Customer"
推荐阅读
- python-3.x - ValueError:尝试共享变量 rnn/multi_rnn_cell/cell_0/lstm_cell/kernel
- python - Gunicorn 无法连接到 Alpine 上的 sock 文件
- php - 弹药口径的正则表达式设计
- python - 如何根据子列表中的条件删除列表元素
- performance - React Native 延迟渲染
- postgresql - Postgres pg_rewind 不适用于简单的用例
- html - 出现换行时如何调整行间距?
- java - 如何为数据库批处理作业选择线程数
- spring - Spring data Mongodb using mongoOperations - 使用查询条件获取嵌套/嵌入数组文档
- java - 如何设置 RatingBar 可点击但不可缩放?