Hello,
we want to set an initial column width and therefore need to activate text wrapping in column headers. I found some messages about this problem in the forum but no solution how to realize that.
Up to now I tried the following:
1. I create a TextColumn in code behind:
TextColumn col = new TextColumn();col.Key = "[rg" + iRG.ToString() + "fct" + iF.ToString() + "]";col.HeaderText = _selFacts[iF - 1].Name;col.Width = new ColumnWidth(100, false);col.HeaderTemplate = (DataTemplate)FindResource("HeaderCellTemplateForTextWrapping");
The Key is created dynamically and the HeaderText is the name of a Fact (e.g. "Turnover [abs.]"). I set the HeaderTemplate.
2. I define the DataTemplate in XAML:
<DataTemplate x:Key="HeaderCellTemplateForTextWrapping" DataType="{x:Type igPrim:HeaderCellControl}"> <TextBlock Text="{Binding HeaderTextProperty}" TextWrapping="WrapWithOverflow" /></DataTemplate>
I alsol tried setting the Datatype to "ig:TextColumn" and tried different Bindings like:
Text="{Binding Path=TextColumn.HeaderText}" Text="{Binding Path=HeaderText}" Text="{Binding Path=HeaderTextProperty}" Text="{Binding Path=TextColumn.HeaderTextProperty}
Up to now nothing worked. I only get empty header cells. Could you please tell me what I must do to get text wrapping?
Regards
I have been looking into your requirement and the easiest way to achieve text wrapping of the header of the columns in the XamGrid is to define a header template with a TextBlock and set its ‘TextWrapping’ property. After that you will set this header template to the columns in the ‘ColumnLayoutAssigned’ event of the XamGrid like e.g. :
<DataTemplate>
<TextBlock Text="{Binding}"
TextWrapping="Wrap"/>
</DataTemplate>
…
private void xamGrid1_ColumnLayoutAssigned(object sender, ColumnLayoutAssignedEventArgs e)
{
foreach (var item in e.ColumnLayout.Columns)
item.HeaderTemplate = this.Resources["header"] as DataTemplate;
}
I am attaching a sample application(xamGridHeaderTextWrapping.zip) that shows this approach.
Please let me know, if you need any further assistance on this matter.
Hello Yanko,
thank you for the sample.
According to your sample I changed my application, but I got the same result I already achieved. In the header I only see the key.
This is not what I need. I create all TextColumns dynamically and therefore each column must get an unique key. The text shown in the column header, which I need to wrap, is asigned to the property "HeaderText".
Could you please show me a solution for this constellation?