簡體   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