Hi
The example that has passed me has not yet reached where I need it. Below I describe better what I need. Because I looked at the links and examples sent and my question still remains.
In DataGrid_AutoGeneratingColumn you are statically defining the two columns "Symbol" and "PreviousClose". I want it not to be necessary to pass the columns. In my scenario I will have several columns, as they will be generated dynamically in my DataGrid. My DataGrid is being shared on several screens, there are moments that load 5 columns and other times more or less columns. In my scenario, if the column is of the GridTextColumn type, it should always break a line of text, if the text is greater than the width of the column. And then the height of the line adjusts to the content.
In my code example, replace "Symbol" and "PreviousClose" with "Field1" and "Field2". But I don't want to have to pass the fields that will have a line break.
namespace TechPosto.Library.Presentation.Helpers
{
using Syncfusion.UI.Xaml.Grid;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Interactivity;
public class QueryRowHeightBehaviour : Behavior
{
GridRowSizingOptions gridRowResizingOptions = new GridRowSizingOptions();
List excludeColumns = new List();
double Height = double.NaN;
protected override void OnAttached()
{
this.AssociatedObject.QueryRowHeight += AssociatedObject_QueryRowHeight;
this.AssociatedObject.AutoGeneratingColumn += AssociatedObject_AutoGeneratingColumn;
}
void AssociatedObject_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e)
{
if (!(e.Column.MappingName == "Campo1") && !(e.Column.MappingName == "Campo2"))
excludeColumns.Add(e.Column.MappingName);
else
(e.Column as GridTextColumn).TextWrapping = TextWrapping.Wrap;
gridRowResizingOptions.ExcludeColumns = excludeColumns;
}
void AssociatedObject_QueryRowHeight(object sender, QueryRowHeightEventArgs e)
{
if (this.AssociatedObject.IsTableSummaryIndex(e.RowIndex))
{
e.Height = 24;
e.Handled = true;
}
else if (this.AssociatedObject.GridColumnSizer.GetAutoRowHeight(e.RowIndex, gridRowResizingOptions, out Height))
{
if (Height > this.AssociatedObject.RowHeight)
{
e.Height = Height;
e.Handled = true;
}
}
}
protected override void OnDetaching()
{
this.AssociatedObject.QueryRowHeight -= AssociatedObject_QueryRowHeight;
this.AssociatedObject.AutoGeneratingColumn -= AssociatedObject_AutoGeneratingColumn;
}
}
}