名称在名称空间中不存在 [英] Name does not exist in the namespace

查看:92
本文介绍了名称在名称空间中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在VS 2015中使用数据模板绑定来开发一个简单的UWP项目。每当我尝试为Datatemplate指定类型时,都会收到错误消息。

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>

这是此类:

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

错误显示为:名称 NavItem在 using:Adaptive_News_Layout命名空间中不存在

推荐答案

我发现了问题所在。这是Visual Studio 2015中的一个小问题。在XAML中添加名称空间后,最好编译/测试运行程序,否则会出现此问题。要解决此问题,只需:

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. 删除所涉及的命名空间引用及其引用的所有用法。

  2. 执行测试运行/编译程序。

  3. 将名称空间引用重新添加到开始页面标记中

  4. 执行另一次测试运行/编译程序。

  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.

这篇关于名称在名称空间中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆