开发者

DataGridCheckBoxColumn OnClick event not firing on first click

I face a strange issue with an OnClick event in DataGridCheckBoxColumn which is not firing on the very first check/unchecked click. Here are some code samples from the xaml, code-behind and view model:

XAML

<DataGrid.Columns>
    <DataGridCheckBoxColumn Width="1*"
                            Binding="{Binding IsAssigned, UpdateSourceTrigger=PropertyChanged}"
                            IsReadOnly="False">
        <DataGridCheckBoxColumn.CellStyle>
            <Style>
                <EventSetter Event="CheckBox.Click"
                             Handler="OnClick" />
            </Style>
        </DataGridCheckBoxColumn.CellStyle>
    </DataGridCheckBoxColumn>
</DataGrid.Columns>

The "IsAssigned" is a bool property that is available in the binded Object. That works absolutly fine.

Code behind

public void OnClick(object sender, RoutedEventArgs e)
{
    // Retrieving the parameter object from sender
    // and doing some other stuff here...
    // ...
    viewModel.ObjectsToChange(parameterObjectFromDataGridCell);
}

View model

internal void ObjectsToChange(object parameterObjectFromDataGridCell)
{
    // do some stuff
}

Why not using OnChecked/OnUnchecked events?

I do not use the OnChecked or OnUnchecked events because they get triggered during load of the DataGrid. As I did not find a solution to differentiate between the initial load and a real Checked/Unchecked event triggered by the user, I decided to try to OnClick event.

Questio开发者_运维百科n:

Why does it ignore the very first check/uncheck click? Any further clicks are recognized.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜