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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:04:03+00:00 2026-05-19T10:04:03+00:00

I have quite a simple question regarding WPF. I’ve searched around but didn’t find

  • 0

I have quite a simple question regarding WPF. I’ve searched around but didn’t find the “the Answer” yet…

I would like to do a 2-level Data Binding. Simplified, I have a Person with some attributes, that also has N Addresses, each of some type and with some Zip Code (both selectable from a combo).

I retrieve the following Data from the server:

public List<AddressType> AddressTypeList; // catalogue of Address Types
public List<ZipCode> ZipCodeList; // catalogue of Zip Codes

public Person Person; // Person object
public List<Address> PersonAddressList; // Address List for that person (each has AddresType and ZipCode property)

Now, I’d like to bind this data to some controls. So, I put these properties into some custom class (say Data) and set the main user control’s DataContext property to this object:

data = new Data();            

data.AddressTypeList = dao.GetAll<AddressType>();
data.ZipCodeList = dao.GetAll<ZipCode>();
data.Person = dao.GetPerson();
data.PersonAddressList = dao.GetPersonAddressList(Person);

this.DataContext = data; // this == some parent UserControl

Now, my XAML part for Address List looks something like this:

<ListBox Name="listBoxAddressList" ItemsSource="{Binding PersonAddressList}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <ComboBox ItemsSource="{Binding AddressTypeList}" SelectedItem="{Binding AddressType}"/>  
                <TextBox Text="{Binding Address}"/> <!-- this works! -->
                <ComboBox ItemsSource="{Binding ZipCodeList}" SelectedItem="{Binding ZipCode}"/>  
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

The Address property gets bound OK, but the AddressTypeList and ZipCodeList don’t. It’s kind of logical, since the PersonAddress (in PersonAddressList) doesn’t have that property (they are on a different level!). I don’t want to put the whole list of AddressTypes and ZipCodes into each address object, I would like to most painlessly bind it to “parent” or pass it to each Address List Item object somehow in XAML.

I think it’s a common request to have a catalogue of some values in a combo (one list), but one of them is selected and that value is bound to another object’s property. How would that be done properly?

  • 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-19T10:04:03+00:00Added an answer on May 19, 2026 at 10:04 am

    Edit 2: You could also try to set up your lists as static properties, that way you might be able to bind directly using something like:

    ItemsSource="{Binding Source={x:Static local:Data.AddressTypeList}}"
    

    Edit: Try using RelativeSource to get back to the original data, something like this:

    <ComboBox ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=ListBox}, Path=DataContext.AddressTypeList}" SelectedValue="{Binding AddressType}"/>
    

    Also: Bind SelectedValue to the property instead of SelectedItem.

    e.g.

    <ItemsControl ItemsSource="{Binding Data}" Grid.IsSharedSizeScope="True">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition SharedSizeGroup="A"/>
                        <ColumnDefinition SharedSizeGroup="B"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0" Text="{Binding Name}"/>
                    <ComboBox Grid.Column="1" SelectedValue="{Binding Occupation}">
                        <sys:String>Programmer</sys:String>
                        <sys:String>GUI Designer</sys:String>
                        <sys:String>Coffee Getter</sys:String>
                    </ComboBox>
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to PHP OOP and I have a question regarding a simple
The question is quite simple : I have a controller plugin for Zend Framework.
I have a problem that is quite simple to understand, but for me it
I am stuck with something quite simple but really annoying: I have an xml
I have a seemingly simple problem, but I can't quite figure out a solution.
I have a simple, general question regarding a real small issue that bothers me:
I asked this question earlier but regarding another programming languages. Let's say I have
This is a question regarding a very simple construction - I have the following
I have a simple question regarding PHP Classes. Multiple times I have seen other
This might seem like a simple question. But I have been looking for an

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.