2016-07-05 164 views
4

我正在使用VS 2015中的数据模板绑定来处理简单的UWP项目。当我尝试指定Datatemplate的类型时,出现错误。名称空间中不存在名称

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” 这个名字并不在命名空间中存在 “使用:Adaptive_News_Layout”

+0

“地方”是如何申报的? – AlexDrenea

+0

尝试构建解决方案,看看是否有任何构建错误。并重新启动VS检查错误是否持续。 –

+0

同样的情况在这里,你有这个工作吗? –

回答

0

我想出了问题所在。这是Visual Studio 2015中的一个小故障。在XAML中添加命名空间后,最好编译/测试运行你的程序,否则你会遇到这个问题。修复它只是:

  1. 删除有问题的名称空间引用和该引用的所有用法。
  2. 执行测试运行/编译您的程序。
  3. 将名称空间参考添加回开始页面标记
  4. 执行另一个测试运行/编译您的程序。
现在,当您使用新的名称空间引用编译器不会出现问题。

+0

典型Micosh * t'功能'... –

0

您必须在ypur Xaml文件的顶部找到部分声明'local'命名空间。 你会看到很多带有格式xmlns的名字空间:Name =“value” 用名字= local和Value命名空间添加你的名字空间

+0

这是我的程序的开始页面标记:“本地”命名空间在那里声明'' –

+0

第5行读取** xmlns:local =”using:Adaptive_News_Layout“** –

相关问题