private void UserControl_Loaded(object sender, RoutedEventArgs e) { // 不要在设计时加载数据。 // if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) // { // //在此处加载数据并将结果指派给 CollectionViewSource。 // System.Windows.Data.CollectionViewSource myCollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["Resource Key for CollectionViewSource"]; // myCollectionViewSource.Source = your data // } Fixed_management.FixedDataSet fixedDataSet = ((Fixed_management.FixedDataSet)(this.FindResource("fixedDataSet"))); // 将数据加载到表 nature 中。可以根据需要修改此代码。 Fixed_management.FixedDataSetTableAdapters.fixed_detalTableAdapter fixed_detalTableAdapter = new Fixed_management.FixedDataSetTableAdapters.fixed_detalTableAdapter(); fixed_detalTableAdapter.Fill(fixedDataSet.fixed_detal); System.Windows.Data.CollectionViewSource fixed_detalViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("fixed_detalViewSource"))); fixed_detalDataGrid.CanUserAddRows = false; }