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
500
XamGrid - How to wrap text in header cells
posted

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

 

Parents
  • 35319
    posted

    Hello,

     

    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.

    xamGridHeaderTextWrapping.zip
Reply Children