Saturday, April 16, 2016

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....
}

0 comments:

Post a Comment