我无法获得SelectedItem
,行选择有效,但已重试SelectedItem
为null
。
查看型号:
// Binding DataGrid ItemSource
public ObservableCollection<Message> TableDataGrid_ItemSource { get; set; }
// Binding DataGrid SelectedItem
private Message _tableDataGrid_SelectedItem;
public Message TableDataGrid_SelectedItem
{
get { return _tableDataGrid_SelectedItem; }
set { _tableDataGrid_SelectedItem = value;
MessageRemovetButton_IsEnabled = true;
OnPropertyChanged(); }
}
XAML:
<DataGrid
Name="TableDataGrid"
ItemsSource="{Binding TableDataGrid_ItemSource}"
AutoGenerateColumns="False"
SelectedItem="{Binding TableDataGrid_SelectedItem, Mode=TwoWay}"
IsReadOnly="True" SelectionUnit="FullRow"
>
代码:
MessageBox.Show(_messageManagerViewModel.TableDataGrid_SelectedItem);