Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
595
HeaderTemplate Binding
posted

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 control
public 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>