Name does not exist in the namespace
Asked Answered
W

4

8

I am working on a simple UWP project using data template binding in VS 2015. When ever I try to specify the type for the Datatemplate I get an error.

XAML:

<Page x:Name="RootPage"
x:Class="Adaptive_News_Layout.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:Adaptive_News_Layout"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" FontSize="22" >

 <SplitView x:Name="MySplitView" Grid.Row="1" DisplayMode="CompactOverlay" Background="LightGray" OpenPaneLength="200"  >
            <SplitView.Pane>
                <ListView x:Name="MyListview" ItemsSource="{x:Bind NavigationItems}"  >
                    <ListView.ItemTemplate>
                        <DataTemplate x:DataType="local:NavItem" >
                            <StackPanel Orientation="Horizontal">
                                <RelativePanel>
                                    <Button x:Name="Icon"  FontFamily="Segoe MDL2 Assets" Content="{x:Bind ButtonIcon}" Width="50" Height="50"/>
                                    <TextBlock x:Name="Section" Text="{x:Bind SectionTitle}" RelativePanel.RightOf="Icon" />
                                </RelativePanel>
                            </StackPanel>
                        </DataTemplate>
                    </ListView.ItemTemplate>

This is the class:

namespace Adaptive_News_Layout
{
    public class NavItem
    {
        public string ButtonIcon { get; set; }
        public string SectionTitle { get; set; }
    }
}

The error reads: The name "NavItem" does not exist in the namespace "using:Adaptive_News_Layout"

Woodchuck answered 5/7, 2016 at 1:41 Comment(5)
how is "local" declared?Parnell
Try building the solution see if there is any build error. And restart VS check if the error persist.Jorgejorgensen
Same situation here, did you get this working?Cuda
xmlns:local="using:Adaptive_News_Layout"Woodchuck
These kinds of errors are so annoying and waste so much time ><Determination
W
9

I figured out what the problem was. It's a glitch in Visual Studio 2015. After you add a namespace in XAML it's best to compile/ test run your program or you will get this problem. To fix it just:

  1. Delete the namespace reference in question and all usages of that reference.
  2. Perform a test run/ compile your program.
  3. Add the namespace reference back into the opening page tag
  4. Perform another test run/ compile your program.
Now when you use your new namespace reference the compiler won't glitch out.
Woodchuck answered 31/5, 2017 at 5:12 Comment(1)
Still happening in VS2019. In my case the namespace existed but I hadn't compiled since I'd added new classes to it. Removed the offending XAML, compiled, re-added it and error went away.Illailladvised
O
1

What worked for me was specifying the assembly in the namespace reference, that is: xmlns:the_namespace="clr-namespace:the_namespace" - produces the above error. xmlns:the_namespace="clr-namespace:the_namespace;assembly=the_assembly" - works well.

Olivia answered 10/1, 2021 at 18:47 Comment(0)
I
0

I found that I had unintentionally defined the same object in a sub-namespace. once I got rid of the second definition, this problem disappeared

Ixia answered 7/12, 2018 at 17:48 Comment(0)
Q
-1

You have to declare 'local' namespace in section which can be found on the top of ypur Xaml file. You will see many namespace with format xmlns:Name ="value" Add your name space with Name =local and Value as your Namespace

Queen answered 5/7, 2016 at 3:2 Comment(2)
This is the opening page tag of my program: The "local" namespace is declared there '<Page x:Name="RootPage" x:Class="Adaptive_News_Layout.MainPage" xmlns="schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Adaptive_News_Layout" xmlns:d="schemas.microsoft.com/expression/blend/2008" xmlns:mc="schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" FontSize="22" >'Woodchuck
The 5th line reads xmlns:local="using:Adaptive_News_Layout"Woodchuck

© 2022 - 2024 — McMap. All rights reserved.