Hi,
this is my code:
<ig:XamGrid ItemsSource="{Binding MySource}" AutoGenerateColumns="False"> <ig:XamGrid.Columns> <ig:TextColumn Key="ID" HeaderText="Test" IsReadOnly="True" HeaderTemplate="{StaticResource myTemplate}" /> </ig:XamGrid.Columns> </ig:XamGrid>
And this is my template:
<DataTemplate x:Key="myTemplate"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding }" /> <TextBlock Text="NEW" FontSize="8" Margin="2,0,0,0" Foreground="#FF6394B7" /> </StackPanel></DataTemplate>
If I use this, the actual headertext is ID but it should be Test.So, how can I bind the text in the TextBlock object to the headertext property?
Hello broeckerS,
I have been looking into your post and since the DataContext of the Header’s DataTemplate is the Key of the Column, we cannot bind to the HeaderText of the Column. This is discussed in the following tread :
http://blogs.infragistics.com/forums/t/33593.aspx
I can suggest accessing the HeaderText in code-behind handling the ‘LoadEvent’ of the TextBlock like :
private void TextBlock_Loaded_1(object sender, RoutedEventArgs e)
{
(sender as TextBlock).Text = (((sender as TextBlock).Parent as StackPanel).Parent as HeaderCellControl).Column.HeaderText;
}
If you have any other questions, feel free to ask.
Thank you for your answer.
This works but it would be nice, to have access to the Column in a future version... ;)
I have converted your suggest to a databinding... so I don't need to work with the code.
Here is my solution:
<DataTemplate x:Key="myTemplate"> <TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=igPrim:HeaderCellControl, AncestorLevel=1}, Path=Column.HeaderText}" /> </DataTemplate>
Thank you for your feedback. I am very glad that you have managed to achieve the functionality that you are looking for.
Please let me know if you have any further assistance.