My requirement is that I need to bind a user control to a Property of an object,whose list is enclosed within a different object and the list of the second object is set as the ItemsSource.
Example
class A
{
public string Name
{
get; set;
}
}
class B
{
public List<A> aObjectList;
}
List<B> bObjectsList = new List<B>();
userControl.ItemSource = bObjectsList;
userControl.Content = new Binding("Name");
How do I do the above thing???
First off, if you want to allow the GUI to update itself when something changes, you should use an implementation of
NotifyCollectionChanged, for instance theObservableCollection<T>.The XAML would look like this:
That is, assuming that your UserControl is an ItemsControl. Then in the code do:
A good idea would be to look at the MVVM Pattern. This will provide a more structured solution, allowing things like modification notices etc.
Here is a good article to get you started.