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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:24:32+00:00 2026-05-17T23:24:32+00:00

Consider a book shelf, it has shelves and each shelf has a number of

  • 0

Consider a book shelf, it has shelves and each shelf has a number of books on it. In turn each book has a few properties such as Title and Author and perhaps ISBN.

namespace mySillyExample
{
  public class BookShelf
  { 
    public Shelf[] myShelves{get; set;}
  }

  public class Shelf
  {
    public Book[] booksOnThisShelf{get; set;}
  }

  public class Book
  {
    public string Title {get; set;};
    public string Author{get; set;};
    public string ISBN {get; set;};
  }
}

Now I would like to make a list box in XAML using WPF to list all of the Titles. Right now my solution looks something like this:

<ListBox Height="154" HorizontalAlignment="Left" 
         ItemsSource="{Binding Path=BookShelf.myShelves}"                  
         Margin="171,475,0,0" VerticalAlignment="Top" Width="333" >
  <ListBox.ItemTemplate>
    <DataTemplate>
      <TextBlock Text="{Binding Path=booksOnThisShelf.[0].Title}" />
    </DataTemplate>
  <ListBox.ItemTemplate>
</ListBox>

And I do get a list box with that data. There are three problems that I see with the above solution.

  1. The DataTemplate tag seems to be designed to change what kind of control the list box will consist of and NOT to provide additional binding scope as it was used

  2. I seem to be referencing the 0th (zeroth/first) element in the array of books for each shelf (“booksOnThisShelf.[0]”) this seems most evil, at it does not seem to be what is happening if I do infact get a list of all of my books (which I do)

  3. This seems to work for 2 layers of lists, but what about 3 or 4 or 42?

Please keep in mind that I can’t change the classes directly (they are generated in XSD) though the potential for a helper class is not necessarily out of the question.

The more I thought about this problem, the more I am convinced it must arise for more people, especially when working with data from Complex XML structures (webpages? give me all of the urls for img tags etc)

So in summary here is what I am looking for:

  1. What is the best way to handle the above issue?
    • Most Elegant/Reusable Model that is preferably maintained in XAML
  2. How can this be abstracted to n-layered lists (object containing a list of objects containing a list of objects . . . ad infinitum/nauseam)?
    • Using my example, what if you had a Room class with multiple BookShelves, and a Library class with multiple Rooms and a City class with multiple Libraries.

As always thanks in advance!

NOTE: I used the term “list” and the code shows an array, my apologies for confusion

  • 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-05-17T23:24:32+00:00Added an answer on May 17, 2026 at 11:24 pm

    I’d suggest at looking at the MVVM pattern. You don’t bind to your Models, but you bind to your ViewModels. You’re ViewModel is what will help you get your giant list. You’d probably want to do something like so:

    //ViewModelBase should be a base class that implements INotifyPropertyChanged
    public class MyViewModel : ViewModelBase
    {
         public readonly IDataProvider _provider;
    
         public MyViewModel(IDataProvider provider)
         {
             _provider = provider ?? (some default provider);
         }
    
         public IList<String> Titles
         {
             get
             {
                  var q = from shelves in _provider.GetBookShelves()
                          from books in shelves.booksOnThisShelf
                          select books.Title;
    
                  return q as List<String>;
             }
         }
    }
    

    Then you just need to set MyViewModel as your DataContext and bind to Titles. Of course, you don’t have to pass in an IDataProvider, you can pass in the list of BookShelves but it’s always best to have a DataProvider get your Model information for you.

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

Sidebar

Related Questions

Consider the following scenario:- A bookstore website has number of books and each book
Consider the following, simplified class: class Book { string title; Author author; } Simple
Consider the models: class Author(models.Model): name = models.CharField(max_length=200, unique=True) class Book(models.Model): pub_date = models.DateTimeField()
Consider the following data set in a book table (group_id, title, check_out_date): > 1
Consider this example from w3schools : <?xml version=1.0 encoding=ISO-8859-1?> <bookstore> <book category=COOKING> <title lang=en>Everyday
I am writing an app to simulate a marketplace for books. Consider a book
Please consider this file: http://www.w3schools.com/dom/books.xml where line: <book category=children> is replaced with: <book category=
Consider I have 2 entities - a) Publisher b) Book Publisher has navigation property
Consider following XML document fragment: <Book> <Title>Example</Title> <Content> Some line </Content> <TOC> Again some
Consider this class hierarchy: Book extends Goods Book implements Taxable As we know, there

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.