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"
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With