简体   繁体   中英

The name "Customer does not exist in the namespace "using:...." UWP

So, im new to UWP and im trying to make some sort of an app in UWP, where i want to print a list of Customers into the window so to speak. my XAML code looks like this:

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="100"/>
        </Grid.RowDefinitions>

        <ListView ItemsSource="{x:Bind local:Customer}">
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="data:Customer">
                    <StackPanel>
                        <TextBlock FontSize="16" Text="{x:Bind Name}"/>
                         <TextBlock FontSize="10" Text="{x:Bind Address}"/>
                        <TextBlock FontSize="10" Text="{x:Bind PhoneNumber}"/>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>



        <TextBlock Grid.Row="1" Name="ResultTextBlock" FontSize="24" Foreground="Red" FontWeight="Bold" Margin="0,20,0,0"/>
    </Grid>

What gives me an error is this:

<DataTemplate x:DataType="data:Customer">

I've been trying to look up an answer that could help, using my Solution name

using UwpNavigationTest1;

In all my files, doesnt make it go away. I cant really find the .VS file to remove, like a hidden file. Is there any other fix to this?

Kind Regards

Derive from official document When using {x:Bind} with data templates, you must indicate the type being bound to by setting an x:DataType value, as shown in the Examples section .

The name “Customer does not exist in the namespace ”using:…" UWP

If you just place Customer class under the project's root folder, please replace x:DataType="data:Customer" with x:DataType="local:Customer" . And if the Customer class in other namespace but not current project namespace, please using the namespace in xaml like the following.

<Page
    x:Class="ListViewTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:core="using:Microsoft.Xaml.Interactions.Core"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity" 
    xmlns:data="using:ListViewTest.Model"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
    mc:Ignorable="d">
......

 <DataTemplate x:Key="DemoItemTemplate" x:DataType="data:Item">

For more info please refer UWP binding depth document.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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