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
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?
|
<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> |
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
Hi Mohanram
Thanks
No problem
Michele
Many thanks Mohanram
I will add the code to project resources and test it.
Regards
Michele