我将Windows窗体中的客户端注册的基本设计传递给WPF,我在代码中遇到了WPF没有selectedRow的问题,然后立即出现了DataBoundItem。 有谁知道如何为WPF转录此代码?
Customer clienteSelecionado = (dataGridPrincipal.SelectedRows [0] .DataBoundItem as Customer);
dataGridPrincipal:是我的DataGrid
答案 0 :(得分:0)
假设DataGrid
的用户界面是这样的:
<DataGrid Name="dataGridPrincipal" Grid.Row="0"
ItemsSource="{Binding MyList}"
SelectedItem="{Binding MyItem , Mode=TwoWay}"
/>
后面的代码如下:
public ObservableCollection<Customer> MyList { get; set; }
public Customer MyItem { get; set; } // with INotifyPropertyChanged implemented
public MainWindow()
{
InitializeComponent();
MyList = YourDataProvider.YourData();
DataContext = this;
}
那么这就是你要找的东西:
var clienteSelecionado = dataGridPrincipal.SelectedItems[0] as Customer;