|
Note: Set ColumnSizer to Auto to get the width of the column to be sized based on the cell text size.
|
|
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
Button button = new Button();
button.Text = "Change font size";
button.Clicked += Button_Clicked;
layout.Children.Add(button);
}
private void Button_Clicked(object sender, EventArgs e)
{
dataGrid.Columns.ForEach(x => x.CellTextSize = 20);
dataGrid.QueryRowHeight += DataGrid_QueryRowHeight;
}
private void DataGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e)
{
if (e.RowIndex > 0)
{
e.Height = SfDataGridHelpers.GetRowHeight(dataGrid, e.RowIndex);
e.Handled = true;
}
}
}
|
|
public partial class MainPage : ContentPage
{
int a = 0;
public MainPage()
{
InitializeComponent();
dataGrid.QueryRowHeight += DataGrid_QueryRowHeight;
Button button = new Button();
button.Text = "Change font size";
button.Clicked += Button_Clicked;
layout.Children.Add(button);
}
private void Button_Clicked(object sender, EventArgs e)
{
if(a%2==0)
{
dataGrid.Columns.ForEach(x => x.CellTextSize = 50);
a++;
}
else
{
dataGrid.Columns.ForEach(x => x.CellTextSize = 100);
a++;
}
dataGrid.GridColumnSizer.Refresh();
dataGrid.View.Refresh();
}
private void DataGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e)
{
if (e.RowIndex > 0)
{
e.Height = SfDataGridHelpers.GetRowHeight(dataGrid, e.RowIndex);
e.Handled = true;
}
}
}
|
|
public partial class MainPage : ContentPage
{
int a = 0;
public MainPage()
{
InitializeComponent();
dataGrid.QueryRowHeight += DataGrid_QueryRowHeight;
Button button = new Button();
button.Text = "Change font size";
button.Clicked += Button_Clicked;
layout.Children.Add(button);
}
private void Button_Clicked(object sender, EventArgs e)
{
if(a%2==0)
{
dataGrid.Columns.FirstOrDefault(x => x.MappingName == "ShipCity").CellTextSize = 50;
a++;
}
else
{
dataGrid.Columns.FirstOrDefault(x => x.MappingName == "ShipCity").CellTextSize = 100;
a++;
}
dataGrid.GridColumnSizer.ResetAutoWidth(this.dataGrid.Columns["ShipCity"]);
dataGrid.GridColumnSizer.Refresh(true);
dataGrid.View.Refresh();
}
private void DataGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e)
{
if (e.RowIndex > 0)
{
e.Height = SfDataGridHelpers.GetRowHeight(dataGrid, e.RowIndex);
e.Handled = true;
}
}
}
}
|