我正在使用 VS 2015 中的数据模板绑定开发一个简单的 UWP 项目。每当我尝试指定数据模板的类型时,都会收到错误。
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; }
}
}
错误如下:名称空间“using:Adaptive_News_Layout”中不存在名称“NavItem”
我明白问题出在哪里了。这是 Visual Studio 2015 中的一个小故障。在 XAML 中添加命名空间后,最好编译/测试运行您的程序,否则您会遇到此问题。要修复它只需:
- 删除有问题的命名空间引用以及该引用的所有用法。
- 执行测试运行/编译您的程序。
- 将命名空间引用添加回起始页面标记中
- 执行另一次测试运行/编译您的程序。
Now when you use your new namespace reference the compiler won't glitch out.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)