简体   繁体   English

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

[英]Display a simple customer list in UWP

So Im currently copy/paste some code from here: https://docs.microsoft.com/en-us/windows/uwp/get-started/display-customers-in-list-learning-track 因此,Im当前从此处复制/粘贴一些代码: https : //docs.microsoft.com/zh-cn/windows/uwp/get-started/display-customers-in-list-learning-track

The code looks like this: 代码如下:

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>

About x:Bind Customers : it does not seem to autocomplete like it is wrong. 关于x:Bind Customers :好像没有错,它似乎不会自动完成。

About x:DataType="local:Customer" : I get the error message The name "Customer" does not exist in the namespace "using:helloUWP" 关于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" });
    }
}

} }

I cannot build it. 我无法建立它。 What am I missing or doing wrong? 我想念什么或做错什么?

To use a custom class in XAML, you first must declare the appropriate namespace in the root element, like for Page : 要在XAML中使用自定义类,您首先必须在root元素中声明适当的名称空间,例如对于Page

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

And then use: 然后使用:

x:DataType="models:Customer"

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

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