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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:57:41+00:00 2026-06-18T19:57:41+00:00

I have 3 models: Machine, Part, and Component. On my ui, I have bound

  • 0

I have 3 models: Machine, Part, and Component. On my ui, I have bound one listbox to a list of Machines and a second listbox to the selected Machine’s list of Parts. Now when the user selects a part, I would like to bind a datagrid to the selected part’s list of components. I tried setting the datagrid’s itemssource to:

ItemsSource="{Binding ElementName=PartSelectList, Path=SelectedItem.Components}"

I also tried setting its datacontext and itemssource

DataContext={Binding ElementName=PartSelectList, Path=SelectedItem}

ItemsSource={Binding Components}

However the datagrid does not automatically update if changes are made to the part’s list of components via methods such as

part.Bags.Add(new Component(..));

Anyone have suggestions on how I should approach this?

Update: I have a class MachineCollection which implements INotifyPropertyChanged. In my xaml.cs code I create my MachineCollection object and bind the MainGrid to it’s Machines property:

Page1.xaml.cs:

private MachineCollection machines

public Page1()
{
    machineCollection = new MachineCollection();
    MainGrid.DataContext = machineCollection.Machines 
    actionThread = new Thread(InitLists);
    actionThread.Start();
}

public void InitLists()
{
    machineCollection.Machines.AddRange(dbCon.GetAllMachines());
}

Classes:

public class MachineCollection : INotifyPropertyChanged
{
    public List<Machine> Machines
    {
        get { return machines; }
        set { machines = value; NotifyPropertyChanged("Machines"); }
    }
}

public class Machine : INotifyPropertyChanged
{
    public List<Part> Parts
    {
        get { return parts; }
        set { parts = value; NotifyPropertyChanged("Parts");
    }
}

public class Part : INotifyPropertyChanged
{
    public List<Component> Components
    {
        get { return components; }
        set { components = value; NotifyPropertyChanged("Components");
    }
}

public class Component : INotifyPropertyChanged
{
    public int Length
    {
        get { return length; }
        set { length = value; NotifyPropertyChanged("Length");
    }
}

XAML:

<Page>
<Grid Name="MainGrid">
    <ListBox x:Name="MachineSelectList" HorizontalAlignment="Left" VerticalAlignment="Bottom" 
                 Height="114"  Width="231"
                 Foreground="White" Background="#FF7A7A7A" FontSize="16" BorderBrush="#FFC13131"
                 ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Width="200">
                        <TextBlock Text="{Binding SerialNumber}" TextAlignment="Left" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                        <Button Name="DeleteMachine" Tag="{Binding SerialNumber}" HorizontalAlignment="Right" VerticalAlignment="Center" Height="20"
                                Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" Focusable="False" Click="Btn_Click" >
                            <Image Source="..\Resources\Images\delete.png" Stretch="Uniform"/>
                        </Button>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

    <ListBox Name="PartSelectList" HorizontalAlignment="Left" VerticalAlignment="Bottom" 
                 Height="164"  Width="231"
                 Background="#FF7A7A7A" Foreground="White" FontSize="16" BorderBrush="#FFC13131"
                 ItemsSource="{Binding Path=Parts}" IsSynchronizedWithCurrentItem="True">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Width="200">
                        <TextBlock Text="{Binding PartNumber}" TextAlignment="Left" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                        <Button Name="DeletePart" Tag="{Binding PartNumber}" HorizontalAlignment="Right" VerticalAlignment="Center" Height="20"
                                Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" Focusable="False" Click="Btn_Click" >
                            <Image Source="..\Resources\Images\delete.png" Stretch="Uniform"/>
                        </Button>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

</Grid>
</Page>
  • 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-18T19:57:43+00:00Added an answer on June 18, 2026 at 7:57 pm

    One way to solve this is using ObservableCollection, which is made for situations like this.

    public ObservableCollection<Part> Parts
    {
        get { return parts; }
        set { parts = value; NotifyPropertyChanged("Parts");
    }
    

    Or you could implement the interface INotifyCollectionChanged manually

    The problem is, basically, that the binding system does not know when you call Add. If you were reassigning the Parts property each time, then the system would just redraw everything, so it would reflect the changes too, but if ObservableCollection is not a problem, that’s the prefered way

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

Sidebar

Related Questions

I have a rails application with User and Machine data models, as well as
I have three models: class User include Mongoid::Document field :name, :type => String has_many
I'm writing a Rails app in which I have two models: a Machine model
Code: Model: class Machines(models.Model): name = models.CharField(max_length=100, verbose_name=hostname, help_text=Host name of the machine) ip_addr
I am looking to implement a state machine in one of my models, and
I have a Django model with a decimal field: class User(models.Model): ... balance =
I have created a simple state machine model in Enterprise Architect and exported it
I have models like this: class Vendor(models.Model): title = models.CharField() class Product(models.Model): ... vendor
I have models Product and Category . Category can have many products. ( Product
I have models like this: class IdfPracownicy(models.Model): nazwa = models.CharField(max_length=100) class IdfPracaOpinie(models.Model): nazwa =

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.