WPF에서 DataGrid를 보유하고 있습니다. SelectedItem 속성을 바인딩했습니다. 선택한 행을 제거하는 제거 단추가 있습니다. 그러나 다른 곳 (예 : TextBox)을 클릭하면 DataGrid에서 포커스를 잃었을 때 SelectedItem이 변경되지 않습니다. 내가 "이전에"선택된 행을 제거 할 수 있습니다.DataGrid가 포커스를 잃어 버렸지 만 SelectedItem이 null로 설정되지 않았습니다.
예상대로 동작합니까? 쉽게 고칠 수 있습니까?
편집 (요청에 따라 코드) :
<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));
}
}
삭제 및 바인딩 게시. – Paparazzi