Let's assume we have data grid like this:
<DataGrid Name="DataGrid1" SelectionMode="Single"
SelectionChanged="DataGrid1_SelectionChanged">
</DataGrid>
and event handler in code behind (xaml.cs file):
private void DataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var item = DataGrid1.SelectedItem;
if (item != null)
{
}
}
You should
cast selected item to type of your business object.
If you are using
anonymous types, you can use combination of the
Selector.SelectedValuePath Property[
^] and
Selector.SelectedValue Property[
^].