ColumnHeader Multline

Header.JPG 

Hello

I need to set sfDataGridHeaders with multiline text.

Actually i'm using this code:


        public static DataTemplate GetHeaderTemplate(ColumnMap mapping)

        {

            if (mapping.HeaderTextLines == null) return null;


            Style HeaderStyle = new Style(typeof(GridHeaderCellControl));

            HeaderStyle.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty, mapping.HeaderAlignment));


            FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(StackPanel));

            spFactory.SetValue(StackPanel.OrientationProperty, Orientation.Vertical);

            spFactory.SetValue(StackPanel.VerticalAlignmentProperty, VerticalAlignment.Center);


            for (int i = 0; i < mapping.HeaderTextLines.Length; i++)

            {

                FrameworkElementFactory textLine = new FrameworkElementFactory(typeof(TextBlock));

                textLine.SetValue(TextBlock.TextProperty, mapping.HeaderTextLines[i]);

                textLine.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);



                spFactory.AppendChild(textLine);

            }


            DataTemplate dt = new DataTemplate();

            dt.VisualTree = spFactory;


            return dt;

        }


The code works well but the result is "cutted" (see picture).


How can i fix this behavior?

Thanks 

Michele



11 Replies

MA Mohanram Anbukkarasu Syncfusion Team July 19, 2021 09:46 AM UTC

Hi Michele, 

Thanks for the update.  

We have checked the provided code snippet and prepared a simple sample to replicate your scenario. But unfortunately, we are unable to reproduce the reported issue in our end.  

 


Please have a look at this sample and let us know if we have missed any customization you have done in your application. Otherwise try to reproduce the reported issue in this sample and revert to us with the modified sample. It will be more helpful for us to find the exact cause for the issue and to provide a prompt solution at earlier. 

Regards, 
Mohanram A. 



MI Michele July 19, 2021 12:17 PM UTC


Hello

Thanks for the reply

Your code works fine and i've found the problem but i can still no fix it.

The problem is when usign StackedColumns and set the HeaderRowHeight too low.

In non StackedColumn, the Header's text is "cutted" also if there is space enugh to represent many rows then the StackedColumn


It is possible to fill the Header of non StackedColumns Header without modifing HeaderRow Height? 


Header2.JPG





Attachment: SfDataGrid_Demo_7637f39e.zip


MA Mohanram Anbukkarasu Syncfusion Team July 20, 2021 08:52 AM UTC

Hi Michele, 

Thanks for the update.  

We have checked the provided sample. You can resolve the reported issue by changing the VerticalContentAlignment for the header as Stretch as shown in the following code example.  

Code example :  

<Window.Resources> 
    <Style TargetType="syncfusion:GridHeaderCellControl"> 
        <Setter Property="VerticalContentAlignment" Value="Stretch"/> 
    </Style> 
</Window.Resources> 
        <Grid> 
    <syncfusion:SfDataGrid Name="dataGrid" 
                           AutoGenerateColumns="False" 
                           HeaderRowHeight="50" 
                           ItemsSource="{Binding Employees}"> 
        <syncfusion:SfDataGrid.StackedHeaderRows> 
            <syncfusion:StackedHeaderRow > 
                <syncfusion:StackedHeaderRow.StackedColumns > 
                    <syncfusion:StackedColumn HeaderText="Text" 
                                      ChildColumns="Title,Salary"/> 
                </syncfusion:StackedHeaderRow.StackedColumns> 
            </syncfusion:StackedHeaderRow> 
        </syncfusion:SfDataGrid.StackedHeaderRows> 
        <syncfusion:SfDataGrid.Columns> 
            <syncfusion:GridTextColumn MappingName="FirstName" /> 
            <syncfusion:GridTextColumn MappingName="LastName" /> 
            <syncfusion:GridTextColumn MappingName="ID" /> 
            <syncfusion:GridTextColumn MappingName="Title" /> 
            <syncfusion:GridTextColumn MappingName="Salary"/> 
        </syncfusion:SfDataGrid.Columns> 
    </syncfusion:SfDataGrid> 
</Grid> 


 




Please let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 



MI Michele July 30, 2021 10:15 AM UTC

Thanks  Mohanram

Your code works but in need to manage it programmatically.

Using this snippet with SfDataGrid it runs 

dataGrid.Columns[0].HeaderStyle = GetHeaderStyle();

        public static Style GetHeaderStyle()

        {

            Style HeaderStyle = new Style(typeof(GridHeaderCellControl));

            HeaderStyle.Setters.Add(new Setter(GridHeaderCellControl.VerticalContentAlignmentProperty, VerticalAlignment.Stretch));

            return HeaderStyle;

        }


But similiar code doesn't works with SfTreeGrid

treeGrid.Columns[0].HeaderStyle = GetTreeHeaderStyle();

        public static Style GetTreeHeaderStyle()

        {

            Style HeaderStyle = new Style(typeof(TreeGridHeaderCell));

            HeaderStyle.Setters.Add(new Setter(TreeGridHeaderCell.VerticalContentAlignmentProperty, VerticalAlignment.Stretch));

            return HeaderStyle;

        }


There is a solution via code?


Thanks

Michele




Attachment: SfDataGrid_Demo_572fad86.zip


MA Mohanram Anbukkarasu Syncfusion Team August 2, 2021 12:57 PM UTC

Hi Michele, 

Thanks for the update.  

We are currently validating this in SfTreeGrid. We will check and update with further details on August 4, 2021. We appreciate your patience until then. 

Regards, 
Mohanram A. 



MA Mohanram Anbukkarasu Syncfusion Team August 4, 2021 12:34 PM UTC

Hi Michele,  

We regret for the inconvenience. 

We are still validating this in SfTreeGrid. We will update with further details on August 6, 2021. We appreciate your patience and understanding.  

Regards,  
Mohanram A. 



MI Michele August 4, 2021 02:28 PM UTC

Hi  Mohanram 

Thanks


No problem

Michele



MA Mohanram Anbukkarasu Syncfusion Team August 5, 2021 02:20 PM UTC

Hi Michele, 

Thanks for the update. 

We will check and update on August 6, 2021 as promised.  

Regards, 
Mohanram A. 



MA Mohanram Anbukkarasu Syncfusion Team August 6, 2021 06:16 AM UTC

Hi Michele, 

Thanks for your patience.  

We have analyzed the reported problem in header cell of the SfTreeGrid. We can resolved this. However, it involved xaml code changes. We have modified the sample you have provided in your previous update to resolve this issue and it is available in the following link for your reference.  


Please have a look at this sample and let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 



MI Michele August 6, 2021 11:45 AM UTC

Many thanks  Mohanram 

I will add the code to project resources and test it.


Regards

Michele



MA Mohanram Anbukkarasu Syncfusion Team August 9, 2021 06:12 AM UTC

Hi Michele 

Thanks for the update.  

Please let us know if you require have any other queries.  

Regards, 
Mohanram A.  



Loader.
Up arrow icon