Reputation: 883
So Im currently copy/paste some code from here: https://learn.microsoft.com/en-us/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.
About x:DataType="local:Customer"
: I get the error message 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?
Upvotes: 0
Views: 543
Reputation: 39072
To use a custom class in XAML, you first must declare the appropriate namespace in the root element, like for Page
:
<Page ... xmlns:models="TheNamespaceWhereCustomerIs">
And then use:
x:DataType="models:Customer"
Upvotes: 1