DataTemplate cannot resolve DataType prefix data

The left image is a mistake, and the right one is a Microsoft example.

I am trying to implement ListView in UWP using window code example.

<ListView.GroupStyle>
            <GroupStyle >
                <GroupStyle.HeaderTemplate>
                    <DataTemplate x:DataType="data:GroupInfoList">
                        <TextBlock Text="{x:Bind Key}" 
                                   Style="{ThemeResource TitleTextBlockStyle}"/>
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>
            </GroupStyle>
        </ListView.GroupStyle>

Line -

DataTemplate x: DataType = "data: GroupInfoList"

Gives me the error shown in the left image. When creating models, I propose to create them differently. He says

The data namespace prefix is ​​undefined.

Is this the namespace I need to include?

+4
source share
4 answers

I had the same problem, this page was copied / pasted from a Universal ListView sample.

, .. , , .

+1

data:GroupInfoList - GroupInfoList data.
, .

Page SimpleListViewSample - :

<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">
...

( xmlns:data="HermantsListV2.Model.)

, .

+2

Visual Studio 2015, , . , - .

1- :

<!--<DataTemplate x:DataType="data:GroupInfoList">
          <TextBlock Text="{x:Bind Key}" 
                     Style="{ThemeResource TitleTextBlockStyle}"/>
 </DataTemplate>-->

2- .

3- uncomment this piece of code:

<DataTemplate x:DataType="data:GroupInfoList">
          <TextBlock Text="{x:Bind Key}" 
                     Style="{ThemeResource TitleTextBlockStyle}"/>
 </DataTemplate>

4- run the application.

+2
source

I managed to get this to work sometimes if you cut the code inside your gridview, etc., then save, create and paste it back. I don’t know why, but sometimes it fixes, maybe VS is hiding something there.

+1
source

Source: https://habr.com/ru/post/1611755/


All Articles