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 8934931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:53:06+00:00 2026-06-15T09:53:06+00:00

I am trying to use Bindings with ListBoxes to display a menu which is

  • 0

I am trying to use Bindings with ListBoxes to display a menu which is delivered in a JSON file. The problem is that the content of the “MenuEntryTemplate” below does not get displayed if I use the code below, if I place the listboxes in the CantineTemplate directly and use {Binding Meal.Lunch} and {Binding Meal.Dinner} they do work, so I wonder why adding this extra level breaks the code.

I have the following piece of JSON (for which I cannot change the format):

"cantines": [
    {
        "name": "Canteen A",
        "meal": {
            "lunch": [
                {
                    "type": "soup",
                    "name": "Vegetable soup"
                },
                {
                    "type": "main",
                    "name": "Burger with fries"
                },
            ],
            "dinner": [
                {
                    "type": "main",
                    "name": "Chicken breast with rice"
                }
            ]
        }
    }
]

I deserialize this using Json.Net, which seems to properly deserialize my object into the following data structure:

public class MenuModel : ViewModelBase
{
    public List<Cantines> Cantines { get; set; }
}

public class Cantines
{
    public string Name { get; set; }
    public Meals Meal { get; set; }
}

public class Meals
{
    public List<Lunches> Lunch { get; set; }
    public List<Dinners> Dinner { get; set; }
}

public class Lunches
{
    public string Type { get; set; }
    public string Name { get; set; }
}

public class Dinners
{
    public string Type { get; set; }
    public string Name { get; set; }
}

My XAML looks as follows:

<DataTemplate x:Key="MealEntryTemplate">
    <StackPanel Orientation="Vertical">
        <TextBlock Text="{Binding Type}" />
        <TextBlock Text="{Binding Name}" />
    </StackPanel>
</DataTemplate>

<DataTemplate x:Key="MealTemplate">
    <StackPanel>
        <!-- These 2 listboxes do not show up, when I leave this MealTemplate out and
             use {Binding Meal.Lunch} in the "CantineTemplate" it does work. -->
        <ListBox 
            ItemsSource="{Binding Lunch}"
            ItemTemplate="{StaticResource MealEntryTemplate}"
            />
        <ListBox 
            ItemsSource="{Binding Dinner}"
            ItemTemplate="{StaticResource MealEntryTemplate}"
            />
    </StackPanel>
</DataTemplate>

<DataTemplate x:Key="CantineTemplate">
    <ListBox
        ItemsSource="{Binding Meal}"
        ItemTemplate="{StaticResource MealTemplate}"
        />
</DataTemplate>

<DataTemplate x:Key="MenuTemplate">
    <ListBox
        ItemsSource="{Binding Cantines}"
        ItemTemplate="{StaticResource CantineTemplate}"
    />
</DataTemplate>
  • 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-15T09:53:07+00:00Added an answer on June 15, 2026 at 9:53 am
    <ListBox
        ItemsSource="{Binding Meal}"
        ItemTemplate="{StaticResource MealTemplate}"
        />
    

    The property Meal is a single Meals object. A listbox expects a collection of objects, that’s why it isn’t working. You could declare the Meal property as a List<Meals> to make it work, but I don’t see the point of using a listbox if there’s only one element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use set! to modify the thread-local bindings of a var --
Possible Duplicate: Comparing functionality between KeyListeners and Key Bindings I've been trying to use
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am trying to use the java bindings for libsvm: http://www.csie.ntu.edu.tw/~cjlin/libsvm/ I have implemented
I'm trying to use VLC's python bindings to create my own little video player.
I'm trying to understand how to use Bindings in Xcode. I have this class:
I'm trying to use what's below as a DataTemplate for items bound in a
I am trying to use the PHP bindings (php-wkhtmltox) for wkhtmltopdf. The README said
I'm trying to use the Growl Python bindings (Growl.py v0.7 from the Growl repository)
I am trying to use Ninject to compose an object graph in which a

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.