2

I have a question about Windows 10 UWP development using Visual Studio 2015.

I'm trying to use a DataTemplate for my GridView according to this tutorial. The problem I'm having is with my namespace.

I am not allowed to share my exact code for obvious reasons, but I'm wondering if one of you guys might have run into this before. I am getting almost the same error as this person (error code 0x09c4), except my DataTemplate is in my code-behind-file, not global like him/her. Along with that error I'm also getting the illusive "the _name does not exist in the namespace _namespace".

Here is a piece of my xaml file:

<Grid>
...
    <GridView ItemsSource="{x:Bind ViewModel.AssessExItems}">
        <GridView.ItemTemplate>
            <DataTemplate x:DataType="local:AssessExItem">

            </DataTemplate>
        </GridView.ItemTemplate>
    </GridView>
</Grid>

I know the DataTemplate is empty but even if I enter something there it still doesn't work. Here is my code-behind-file for this xaml file:

public sealed partial class AssessmentExample1Screen : Page
{
    public AssessExItemViewModel ViewModel { get; set; }

    public AssessmentExample1Screen()
    {
        this.InitializeComponent();
        this.ViewModel = new AssessExItemViewModel();
    }
}

public class AssessExItem
{
    public int _assessment_id { get; set; }
    public string name { get; set; }
    public string surname { get; set; }
    public string date { get; set; }

    //public EmpAssessItem() { }
}

public class AssessExItemViewModel
{
    private ObservableCollection<AssessExItem> exampleItems = new ObservableCollection<AssessExItem>();
    public ObservableCollection<AssessExItem> AssessExItems { get { return this.exampleItems; } }

    public AssessExItemViewModel()
    {
        //for (int i = 1; i < 3; i++)
        //{
        this.exampleItems.Add(new AssessExItem()
        {
            name = "Cat 777",
            surname = "Botha",
            date = "2015-03-22"
        });
        //}
        this.exampleItems.Add(new AssessExItem()
        {
            name = "XZR 678",
            surname = "Botha",
            date = "2015-03-22"
        });
        this.exampleItems.Add(new AssessExItem()
        {
            name = "TBL 123",
            surname = "Botha",
            date = "2015-03-22"
        });
    }
}

Please help.

Community
  • 1
  • 1
instanceof
  • 1,404
  • 23
  • 30

1 Answers1

6

I reproduced your problem. How to solve : Clean and build or rebuild the solution.And then I tested it,it works. I guess the most possible reason of why it happened is build can update the file mainpage.g.cs which determined where to find the datatype.

   <GridView ItemsSource="{x:Bind ViewModel.AssessExItems}">
        <GridView.ItemTemplate>
            <DataTemplate x:DataType="local:AssessExItem">
                <StackPanel Height="100" Width="100" Background="OrangeRed">
                    <TextBlock Text="{x:Bind name}"/>
                    <TextBlock Text="{x:Bind  surname}" x:Phase="1"/>
                    <TextBlock Text="{x:Bind date}" x:Phase="2"/>
                </StackPanel>
            </DataTemplate>
        </GridView.ItemTemplate>
    </GridView>
Sunteen Wu
  • 10,509
  • 1
  • 10
  • 21
  • 1
    Thanks for the answer! Yeah, I managed to get it to work by also cleaning and rebuilding it. Although I had to manually retype the entire xaml files from scratch, save them, close them, restart visual studio and finally rebuild and run the project BEFORE opening the files again. What's more is this only sometimes works... No idea why but I got it figured out...for now. Don't know for how long though. – instanceof Dec 03 '15 at 07:15