Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9030521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:30:42+00:00 2026-06-16T07:30:42+00:00

The Structure The scenario is that I have a Pivot where each item is

  • 0

The Structure

The scenario is that I have a Pivot where each item is the menu of a certain day. Inside that PivotItem I need to display the dishes on the menu, grouped by category (e.g. soups, desserts, …).

I have implemented this with the MVVM-model.

I thus have the folowing models:

public class Menu{
    public string Date;
    public List<DishList> Categories;
}
public class DishList
{
    public string Category;
    public List<Dish> Dishes;
}
public class Dish
{
    public string Name;
    public string Price;
}

Edit: these are simplified here, the actual structure for each field is like this:

    private string _date;

    //Get_Set
    public string Date
    {
        get
        {
            return _date;
        }
        set
        {
            if (value != _date)
            {
                _date = value;
            }
        }
    }

So the structure would be like this: a PivotElement containt a Menu-object. Inside it, I show Categories, a number of DishLists. Inside that Dishlist, I show the Category and the different Dishes, each with it’s Name and Price. A mockup to make things a bit more clear (pdf-file on SkyDrive); http://sdrv.ms/12IKlWd

I have the following viewmodel

public class MenuViewModel : INotifyPropertyChanged
{
    private ObservableCollection<Menu> _Menus;
}

The view that should implement (the structure) of the desired layout is as following:

<phone:Pivot 
        ItemsSource="{Binding Menus}">
        <phone:Pivot.HeaderTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Date}" />
            </DataTemplate>
        </phone:Pivot.HeaderTemplate>
        <phone:Pivot.ItemTemplate>
            <DataTemplate>
                <ItemsControl
                    ItemsSource="{Binding Categories}">   
                    <TextBlock
                        Text="{Binding Category}"/>
                    <ItemsControl
                        x:Name="Dishes"
                        ItemsSource="{Binding Dishes}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="300"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>

                                    <TextBlock 
                                        Grid.Column="1" 
                                        Text="{Binding Name}"/>
                                    <TextBlock 
                                        Grid.Column="2" 
                                        Text="{Binding Price}"/>
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ItemsControl>
            </DataTemplate>
        </phone:Pivot.ItemTemplate>
    </phone:Pivot>

As you can see, there’s nested databinding to get to the data it needs.

The only code I then do on the page is

DataContext = App.ViewModel;

The Problem

When I launch it up, I get the correct Data displayed in the PivotItems header, and the correct number of PivotItems. Ufortunately, that’s it; the content of the PivotItem stays empty. The first level of databinding thus works, but no further.

The way I was thinking

  • 1st level: each PivotItem is linked to an object of type Menu, with header Menu.Date
  • 2nd level: Inside that PivotItem I set the ItemsSource of a ItemsControl to that Menu.Categories
  • 3rd level : The ItemsSource now is Menu.Categories.Dishes

I have already searched quite a bit and fiddled around with Datacontext and ItemsSource and different kinds of “{Binding …}”, but I can’t get it to work. I would like to do the binding in xaml, and not in the code-behind.

Notes

  • The only function is to display data. The data is stationary and loaded once from a file.
    That’s why I chose ItemsControl instead of ListBox, there is no need to select anything.
  • This is a MVVM-approach to my previous question: Databinding + Dynamic Pivot
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:30:43+00:00Added an answer on June 16, 2026 at 7:30 am

    First off, you’re trying to access a private field in the title so that won’t work. These also have to be properties, not fields.

    <TextBlock Text="{Binding Date}" />
    
    private string Date;
    

    Next you’re binding to Category, which is also private and not a property.

    <TextBlock Text="{Binding Category}"/>
    
    private string Category;
    

    And you’re binding to the Categories field which needs to be a property.

    <ItemsControl ItemsSource="{Binding Categories}">
    
    public List<DishList> Categories;
    

    Even if you correct these issues, you still won’t get what you want because your outer ItemsControl doesn’t have an ItemTemplate.

    <ItemsControl ItemsSource="{Binding Categories}">   
      <TextBlock Text="{Binding Category}"/>
      ...
    </ItemsControl>
    

    Added: Your new error is because the DataTemplate can only have one child element so you need to use a container like a StackPanel.

    <ItemsControl ItemsSource="{Binding Categories}">
      <ItemsControl.ItemTemplate>
        <DataTemplate>
          <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding Category}"/>
            <ItemsControl x:Name="Dishes" ItemsSource="{Binding Dishes}">
              ...
            </ItemsControl>
          </StackPanel>
         </DataTemplate>
       </ItemsControl.ItemTemplate>
    </ItemsControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario I have an TWO datbase tables of exactly the SAME STRUCTURE. The difference
I'm looking for the proper data structure for this scenario. I have boost available
Scenario: I have an application (C#) that expects a SQL database and login, which
The end goal is to have some form of a data structure that stores
I have a scenario that must be so common, but I've not come up
I have a scenario that looks like this: User A is a registered user.
I understand that the proper structure for separation-of-concerns in MVC is to have view-models
I have a general database structure question. In my scenario I happen to be
I have a Scenario that validates that the image I just uploaded exists on
For simplicity lets assume that I have a vector of N matrices each of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.