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

  • Home
  • SEARCH
  • 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 299031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:47:08+00:00 2026-05-12T06:47:08+00:00

I have an object with two arrays of strings. The object is data bound

  • 0

I have an object with two arrays of strings. The object is data bound to a listbox. One list is bound as the list’s ItemsSource. The other, which is the thing causing me trouble, needs to be bound to a combobox that’s part of a DataTemplate that is set to the list’s ItemTemplate. Basically each item on the listbox has the corresponding element of the first list and a combo box that contains the second list. In other words, every item in the list has the same combobox of choices.

The problem comes from the fact that it winds up that the DataTemplate is data bound the first list. I was expecting the DataTemplate to be databound to the object that contains both lists. Now, with that happening, I can’t figure out what kind of binding syntax I need to get at the “parent” of the DataContext, if that’s even possible.

Can someone point me in the right direction?

Thanks!

  • 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-12T06:47:09+00:00Added an answer on May 12, 2026 at 6:47 am

    If I’m understanding you correctly, you can set the DataContext of your ListBox to an instance of a class (in my example I do it in code by: list.DataContext = myclass;) and you want to set the ItemSource of your listbox to a list in the class (ie Items) and the itemssource of your combobox to another list in the class (ie Values). Here’s my xaml that seems to work:

    <ListBox Name="list" ItemsSource="{Binding Items}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding}"/>
                    <ComboBox ItemsSource=
                              "{Binding RelativeSource={RelativeSource FindAncestor, 
                                                        AncestorType={x:Type ListBox}}, 
                                        Path=DataContext.Values}"
                    />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    

    and heres the class that I’m binding to:

    public class AClass
    {
    
        protected List<string> _Items;
        public List<string> Items
        {
            get
            {
                if (_Items == null)
                {
                    _Items = new List<string>();
                }
                return _Items;
            }
        }
    
    
        protected List<string> _Values;
        public List<string> Values
        {
            get
            {
                if (_Values == null)
                {
                    _Values = new List<string>();
                }
                return _Values;
            }
        }
    }
    

    In code I created an instance of AClass, added Items and Values, and set the instance to the DataContext of the listbox.

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

Sidebar

Ask A Question

Stats

  • Questions 291k
  • Answers 291k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you just want to test re-downloading the content, deleting… May 13, 2026 at 6:06 pm
  • Editorial Team
    Editorial Team added an answer .lt() is not a proper function. You are looking for… May 13, 2026 at 6:06 pm
  • Editorial Team
    Editorial Team added an answer rake db:sessions:clear May 13, 2026 at 6:06 pm

Related Questions

I am developing in python a file class that can read and write a
I'm databinding a listbox to an object that contains two array of strings. Each
Classic memcpy gotcha with C arrays as function arguments. As pointed out below, I
I have been playing with javascript arrays and I have run into, what I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.