I have mouse double click event on wpf data grid in code behind as follow:
async void dataGrid_MouseDoubleClick(object o, MouseButtonEventArgs e)
{
var dg = (DataGrid)o;
var item = (MyCustomType)dg.SelectedItem;
await MyAsyncMethod(item.Id);
}
and on line
var dg = (DataGrid)o;
NullReferenceException occured. Morover, I have no way to show value during debugging session. When I change my method to:
async void dataGrid_MouseDoubleClick(object o, MouseButtonEventArgs e)
{
if(o is DataGrid && (o as DataGrid).SelectedItem !=null)
{
await MyAsyncMethod(((MyCustomType)(o as DataGrid).SelectedItem).Id);
}
}
everythings seems to work correctly. How async mouse double click works that I can not invoke event like first representation?