I have a DataGrid in WPF. I have binded SelectedItem property. I have Remove button which removes selected row. However when I click to other place (i.e. TextBox) and DataGrid has lost a focus, SelectedItem does not change. I can Remove the row, that was selected "earlier".
Is it default behaviour you would expected? Can it be easily fixed?
edit (code as requested):
<DataGrid SelectedItem="{Binding SelectedPort}" (...) >
<Button Command="{Binding RemovePortCommand}" >Remove Port</Button>
public ICommand RemovePortCommand
{
get
{
return _removePortCommand ?? (_removePortCommand = new RelayCommand(param => OnRemovePortCommand(), param => SelectedPort != null));
}
}