I have an ItemsControl which has a infragitics grid. I'm binding the ItemsControl to a list of objects. The object has a string that will be use for the first column of the grid and another list that the grid will bind to. How do I bind the string in the object to the first column's header?
Parent Object
public class ParentObj{ public string HeaderText { get; set; } public ObservableCollection<ChildObj> Children { get; set; } public ParentObj() { Children = new ObservableCollection<ChildObj>(); }}
Child Object
public class ChildObj{ public string Name { get; set; } public string Desc { get; set; }}
List that itemscontrol is bounded to and the class constructor for my user controlpublic ObservableCollection<ParentObj> parents = new ObservableCollection<ParentObj>();
public TestControl(){ InitializeComponent(); for(int i = 0; i < 20; i++) { ParentObj p = new ParentObj() { HeaderText = "Parent " + i.ToString(), };
for(int j = 0; j < 10; j++) { ChildObj c = new ChildObj() { Name = "Child " + j.ToString(), Desc = "This is child number " + j.ToString() }; p.Children.Add(c); } parents.Add(p); }
uiItemsControl.ItemsSource = parents;}
XAML
<ItemsControl x:Name="uiItemsControl"> <ItemsControl.ItemTemplate> <DataTemplate> <igGrid:XamWebGrid x:Name="uiChildren" AutoGenerateColumns="False" ItemsSource="{Binding Children}"> <igGrid:XamWebGrid.Columns> <igGrid:TextColumn Key="Name" Width="200" TextWrapping="Wrap"> <igGrid:TextColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding HeaderText}" /> </DataTemplate> </igGrid:TextColumn.HeaderTemplate> </igGrid:TextColumn> <igGrid:TextColumn Key="Desc" HeaderText="Description" TextWrapping="Wrap" /> </igGrid:XamWebGrid.Columns> </igGrid:XamWebGrid> </DataTemplate> </ItemsControl.ItemTemplate></ItemsControl>
Thanks for the reply. I'll see if I can do this another way.
Hi,
So thats not going to work, b/c the DataContext of the Header's DataTemplate, is the Key of the Column. It's not the same as the DataContext of the xamWebGrid.
-SteveZ