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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:38:44+00:00 2026-06-12T02:38:44+00:00

I have a List of objects that contain another List . I want to

  • 0

I have a List of objects that contain another List. I want to bind both Lists to different controls (one nested within the other – a ListView as GridViewItem). But I can’t get the xaml to work.

Very close to this question comes Binding List of Lists in XAML?.
And there is an article regarding this in the MSDN documentation:
How to bind to hierarchical data and create a master/details view – could be the solution, but I find it difficult to apply it to my code.
Other articles touch this topic, but not that good and also as a new user I’m not allowed to include more than two hyperlinks in a question.

My code looks similar to this (changed to city / restaurant scenario for clarity):

Model:

public class City
{
    string Name { get; set; }
    List<Restaurant> RestaurantList { get; set; }
    //.. also a constructor with parameters for the properties and an overriding toString method that returns Name
}
public class Restaurant
{
    string Name { get; set; }
    List<Uri> UriList { get; set; }
    //.. also a constructor with parameters for the properties and an overriding toString method that returns Name
}

Code-behind (LoadState method):

    //.. getting a List of cities (with restaurants), that is being created in some model class
    this.DefaultViewModel["Items"] = Cities;

Some people set the DataContext instead. I got this from the MSDN tutorials and it worked so far. But I’m not sure which is “better”.

Okay now the XAML:

I want to have a GridView with the Cities as GridViewItems. Within one GridViewItem there’s a Grid, displaying the City‘s Name in the top row and a ListView below. The ListView contains the Restaurants (only of that City!). The ListViewItems are only TextBlocks showing the Restaurant‘s Name.
I want only the Restaurants to be clickable.

Like this:
http://imageshack.us/a/img687/5576/listviewasgridviewitem.png

<!-- the following line is at the very top and the reason why it should work without setting DataContext explicitly -->
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
<!-- ... -->
<GridView Grid.Row="1" ItemsSource="{Binding Items}" SelectionMode="None">
    <GridView.ItemTemplate>
        <DataTemplate>
            <Grid Height="500" Width="200" Margin="50" Background="Gray">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition Height="5*"/>
                </Grid.RowDefinitions>
                <TextBlock TextWrapping="Wrap" Text="{Binding Name}"/>
                <ListView
                    Grid.Row="1"
                    ItemsSource="{Binding RestaurantList}" IsItemClickEnabled="True">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" Tapped="Restaurant_Click"/>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Grid>
        </DataTemplate>
    </GridView.ItemTemplate>
</GridView>

This way only gray boxes are shown. When changing the TextBlock‘s binding to Text="{Binding}" then at least the Names of the Cities are shown. Which I don’t understand and also don’t want, because I guess the overriding of the toString methods is not meant to be used this way. The Names of the Restaurants don’t show up in both cases.

Also, the scrolling somehow broke in this view, but that’s a different story I suppose.

So: What’s wrong with the data binding in the XAML?

  • 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-12T02:38:45+00:00Added an answer on June 12, 2026 at 2:38 am

    The databinding engine needs public properties (the link is about WPF but the same concepts apply in WinRT):

    You can bind to public properties, sub-properties, as well as
    indexers, of any common language runtime (CLR) object.

    But if you don’t specify it explicit the compiler treats members by default “the most restricted access you could declare for that member” e.g. private in your case.

    So you need to declare your properties as public:

    public class City
    {
        public string Name { get; set; }
        public List<Restaurant> RestaurantList { get; set; }
    }
    
    public class Restaurant
    {
        public string Name { get; set; }
        public List<Uri> UriList { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of objects that I want to transform into another list
I have a listview that is loaded with a list of objects that contain
Say I have objects A,B,C,D. They can contain references to one another, for example,
I have an list of objects that contains another object in it. List<MyClass> myClass
I have a class Player that contains a list of Accessory objects. There are
I have a Ticket class that contains a List of User objects: class Ticket
I have a list of objects that have two int properties. The list is
I have a List of objects that I would like to convert to a
I have a List of String objects that are pipe delimited. something like this:
I have a list/collection of objects that may or may not have the same

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.