繁体   English   中英

在UWP中显示简单的客户列表

[英]Display a simple customer list in UWP

因此,Im当前从此处复制/粘贴一些代码: https : //docs.microsoft.com/zh-cn/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中使用自定义类,您首先必须在root元素中声明适当的名称空间,例如对于Page

<Page ... xmlns:models="TheNamespaceWhereCustomerIs">

然后使用:

x:DataType="models:Customer"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM