private void DataGridExtendWarrantyRadioButton_Checked(object sender, RoutedEventArgs e) { RadioButton rbtn = sender as RadioButton; //找父表格 var datagrid = UtilityHelper.GetParentObject <DataGrid>(rbtn, "DataGridExtendWarranty"); ExtendedWarrantyVM selectedModel = datagrid.SelectedItem as ExtendedWarrantyVM; //点击当前选项,那其他选项也该被取消选中 var dataGridDataContext = datagrid.ItemsSource as List <ExtendedWarrantyVM>; dataGridDataContext.Where(p => p.SysNo != selectedModel.SysNo).ToList() .ForEach(p => { p.IsCheck = false; }); //主表格需要被选中状态 //查询所在行 var row = UtilityHelper.GetParentObject <DataGridRow>(datagrid, ""); //获取当前绑定的项的值 var data = DataGrid.Columns[0].GetCellContent(row).DataContext as DynamicXml; if (!(bool)data["IsCheck"]) { data["IsCheck"] = true; } //触发绑定数据 var product = GetData((int)data["SysNo"], null); //选中的时候重新new,就不会出现多重的情况 product.ExtendedWarrantyList = new List <ExtendedWarrantyVM>(); product.ExtendedWarrantyList.Add(selectedModel); }
//行模板详细状态改变触发事件 private void DataGrid_RowDetailsVisibilityChanged(object sender, DataGridRowDetailsEventArgs e) { //如果是展开状态将加载数据 if (e.Row.DetailsVisibility == Visibility.Visible) { var data = DataGrid.Columns[0].GetCellContent(e.Row).DataContext as DynamicXml; #region Gift if ((int)data["GiftItemCount"] > 0) { //加载礼品 var giftDataGird = e.DetailsElement.FindName("DataGridGift") as DataGrid; //如果加载过将不再读取 if (giftDataGird.ItemsSource == null) { m_facade.GetValidVenderGifts(data["SysNo"], (o, args) => { if (!args.FaultsHandle()) { var list = args.Result.Rows; foreach (var item in list) { item["IsCheck"] = false; item["MasterSysNo"] = data["SysNo"]; } giftDataGird.ItemsSource = list; } }); } } #endregion #region ExtendWarranty if ((int)data["ExtendWarrantyCount"] > 0) { //加载延保产品 var extendWarrantyDataGird = e.DetailsElement.FindName("DataGridExtendWarranty") as DataGrid; //如果加载过将不再读取 if (extendWarrantyDataGird.ItemsSource == null) { var query = new CategoryExtendWarrantyQueryFilter(); query.PagingInfo = new PagingInfo { PageIndex = 0, PageSize = 10, SortBy = "A.SysNo" }; query.C3SysNo = (int)data["C3SysNo"]; query.MaxUnitPrice = (decimal)data["Price"]; query.MinUnitPrice = (decimal)data["Price"]; m_facade.GetExtendWarranty(query, (o, args) => { if (!args.FaultsHandle()) { List <ExtendedWarrantyVM> vmlist = new List <ExtendedWarrantyVM>(); //将数据转为VMList foreach (var item in args.Result.Rows) { ExtendedWarrantyVM vm = DynamicConverter <ExtendedWarrantyVM> .ConvertToVM(item); vm.ServiceYears = (decimal)item["Years"]; vm.ServiceUnitPrice = item["UnitPrice"]; vm.ServiceCost = item["Cost"]; vmlist.Add(vm); } extendWarrantyDataGird.ItemsSource = vmlist; } }); } } #endregion } }