I'm trying to implement ListView in UWP using Window's sample code.
<ListView.GroupStyle>
<GroupStyle >
<GroupStyle.HeaderTemplate>
<DataTemplate x:DataType="data:GroupInfoList">
<TextBlock Text="{x:Bind Key}"
Style="{ThemeResource TitleTextBlockStyle}"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
The line -
DataTemplate x:DataType="data:GroupInfoList"
Is giving me error, shown in the left image, When creating models am I suppose to create them differently.It says
The namespace prefix "data" is not defined.
Is it a namespace that I need to include?
In your case data:GroupInfoList
is the type GroupInfoList
in the namespace mapping data
.
You have to define the namespace mapping before you can use it.
In the Page
element of SimpleListViewSample
you should have something like this:
<Page
x:Class="HermantsListV2.Sample.SimpleListViewSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:data="HermantsListV2.Model">
...
(Notice the xmlns:data="HermantsListV2.Model
mapping.)
Just replace the namespaces in the example above with the right ones from your project and it should work.
It is a bug in the Visual Studio 2015 to solve it just comment that part of the code and run it. after that uncomment it and it will run without any error.
1- Comment this part of the code:
<!--<DataTemplate x:DataType="data:GroupInfoList">
<TextBlock Text="{x:Bind Key}"
Style="{ThemeResource TitleTextBlockStyle}"/>
</DataTemplate>-->
2- run your app.
3- uncomment this part of code:
<DataTemplate x:DataType="data:GroupInfoList">
<TextBlock Text="{x:Bind Key}"
Style="{ThemeResource TitleTextBlockStyle}"/>
</DataTemplate>
4- run the app.
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