Donate

WPF DataGrid Column Resize Event

Windows Forms DataGridView has a built-in event when the DataGridViewCell is resized but missing in WPF. To add an event for the DataGridCell when it is resized, a solution is to add an EventSetter to the DataGridCell style and then set the values of Handler and Event respectively.
1
2
3
4
5
<DataGrid.CellStyle>
    <Style TargetType="DataGridCell">
        <EventSetter Event="SizeChanged" Handler="Cell_SizedChanged" />
    </Style>
</DataGrid.CellStyle>
In your code behind, add definition to the Handler based from the defined style.
1
2
3
4
5
private void Cell_SizedChanged(object sender, SizeChangedEventArgs e)
{
    DataGridCell cell = (DataGridCell)sender;
    //TODO: Add your code here....
}

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Pass GUID As Parameter To Action Using ASP.NET MVC ContribGrid