WPF C# - databinding on multiple levels
Last question of the day.
I am new to MVVM modelling and have achieved quite a bit with my
understanding of it but I would need guidance on something before I screw
my entire project up by fiddling around.
I have created a model named Person which has the below:
- General info like: ID, FirstName, LastName, FullName, Nationality etc.
- A list of old jobs
- Each job (a separate model) within the old jobs list has data as well
such as YearStarted, YearEnded, Occupation, Company etc.
So my model looks like this:
- Person:
     - ID
     - Name
     - Nationality
     - Jobs:
          - Job1:
               - Occupation
               - Started
               - Ended
               - Salary
          - Job2:
               - Occupation
               - Started
               - Ended
               - Salary
In my view, the list of People shows perfectly. When I click on one of the
people, I am opening a new WPF page with their own control. I have set up
a constructor called ClickedPerson that retrieves the Person Model data of
the person clicked. Works perfectly and I can show the 1st level data such
as the person's Name by Binding as such: {Binding Path=ClickedPerson.Name}
My question is: how can I have an ItemsControl that would show the level 2
and level 3 of that person's data? Meaning, if I were to implement an
ItemsControl where there would be a stackpanel with 1 new UserControl (for
instance) for each OldJob in the person's life and then have that
UserControl's child controls reflect that old job's specific data like the
Occupation or Salary in textboxes => How can I write the binding part in
XAML?
Don't worry about the UI, I can deal with that, it is merely the Binding
part that I am unsure of.
Let me know if I explained it like a blind gorilla ...
 
No comments:
Post a Comment