Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTemplate not able to resolve DataType prefix data

Left Image is the error and the right one is a Microsoft example

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?

like image 774
Hemant-Webo Avatar asked Oct 15 '15 10:10

Hemant-Webo


2 Answers

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.

like image 187
TorbenJ Avatar answered Oct 04 '22 23:10

TorbenJ


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.

like image 25
hoss77 Avatar answered Oct 05 '22 00:10

hoss77