Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在UWP中显示简单的客户列表_C#_Xaml_Uwp_Uwp Xaml - Fatal编程技术网

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

C# 在UWP中显示简单的客户列表,c#,xaml,uwp,uwp-xaml,C#,Xaml,Uwp,Uwp Xaml,所以我现在从这里复制/粘贴一些代码: 代码如下所示: xaml: <ListView ItemsSource="{x:Bind Customers}" HorizontalAlignment="Center" VerticalAlignment="Center"> <ListView.ItemTemplate> <DataTemplate x:DataType="local:Customer"> <Tex

所以我现在从这里复制/粘贴一些代码:

代码如下所示:

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>
}


我不能建造它。我遗漏了什么或做错了什么?

要在XAML中使用自定义类,首先必须在根元素中声明适当的名称空间,如页面:


在没有看到完整的源代码以能够告诉客户实际在哪个命名空间中并给出正确答案的情况下,您也可以完全删除x:DataType声明,并在DateTemplate中将{x:Bind…}替换为{Binding…}x:Bind实际上是在uwp绑定中更有效的绑定方式。绑定会消耗更多资源@JohnnyWestlakery使用不同的体系结构x86或x64清理和重建解决方案,因为如果客户和主页位于命名空间中,那么您的代码应该可以工作。@JohnnyWestlake我现在用完整的代码编辑了我的帖子,因为它看起来像客户已经与MainPage位于同一名称空间中,但当然我猜在这种情况下我不确定是否会出错:-d代码看起来不错,在我看来它是一个vs错误wierd错误,有时会通过清理解决方案得到解决:P
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" });
    }
}
<Page ... xmlns:models="TheNamespaceWhereCustomerIs">
x:DataType="models:Customer"