Polecenie wiązania z obiektu biznesowego do widoku w MVVM
Wypełniam DataGrid w WPF przez MVVM. Mam obiekt biznesowy z 4 właściwościami do utworzenia wiersza i kolumn w DataGrid.
<DataGrid CanUserAddRows="True" ItemsSource="{Binding Path=PersonsInfo}" AutoGenerateColumns="False"
CanUserDeleteRows="True" CanUserReorderColumns="True"
CanUserSortColumns="True">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Path=Name}"/>
<DataGridTextColumn Header="Age" Binding="{Binding Path=Age}"/>
<DataGridTextColumn Header="Date Of Birth" Binding="{Binding Path=DateOfBirth}"/>
<DataGridTextColumn Header="Address" Binding="{Binding Path=Address}"/>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Button Content="Remove..." Margin="3" Command="{Binding Path=RemoveCommand}" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
W powyższym kodzie, gdy klikam przycisk, muszę usunąć rekordy z DataGrid.
Potrzebuję więc wymogu, że powinienem mieć polecenie w klasie obiektu biznesowego, a nie w klasie ViewModel.
Gdy klikam przycisk w każdym wierszu, ten odpowiedni wiersz powinien zostać usunięty.
Jak więc znaleźć element wybrany w DataGrid, aby usunąć wiersz poprzez wykonanie polecenia w klasie obiektu biznesowego, ponieważ klasa obiektu biznesowego nie ma informacji o elementach siatki danych?