public List <List <object> > ExportData() { var result = new List <List <object> >(); var bindingsInfo = new List <BindingInfo>(); var header = new List <object>(); foreach (var column in Columns.OrderBy(p => p.DisplayIndex)) { if (column.Visibility == Visibility.Visible) { if (column is DataGridBoundColumn) { var temp = column as DataGridBoundColumn; bindingsInfo.Add(new BindingInfo() { Type = 0, Path = (temp.Binding as System.Windows.Data.Binding).Path.Path }); if (temp.Header is HeaderFilterBaseModel) { header.Add((temp.Header as HeaderFilterBaseModel).Name); } else { header.Add(temp.Header); } } else if (column is DataGridComboBoxColumn) { var temp = column as DataGridComboBoxColumn; if (temp.TextBinding != null) { bindingsInfo.Add(new BindingInfo() { Type = 0, Path = (temp.TextBinding as System.Windows.Data.Binding).Path.Path }); } else { var binding = System.Windows.Data.BindingOperations.GetBinding(temp, ComboBox.ItemsSourceProperty); bindingsInfo.Add(new BindingInfo() { Type = 1, Path = (temp.SelectedValueBinding as System.Windows.Data.Binding).Path.Path, DisplayPath = temp.DisplayMemberPath, SelectedValuePath = temp.SelectedValuePath, ItemsSourcePath = binding.Path.Path }); } if (temp.Header is HeaderFilterBaseModel) { header.Add((temp.Header as HeaderFilterBaseModel).Name); } else { header.Add(temp.Header); } } } } result.Add(header); foreach (var item in ItemsSource) { var row = new List <object>(); foreach (var binding in bindingsInfo) { switch (binding.Type) { case 0: row.Add(BindingUtils.Eval(item, binding.Path)); break; case 1: var itemsSource = BindingUtils.Eval(item, binding.ItemsSourcePath) as IEnumerable; if (itemsSource == null) { row.Add(null); break; } var v = BindingUtils.Eval(item, binding.Path); foreach (var comboBoxItem in itemsSource) { var v1 = BindingUtils.Eval(comboBoxItem, binding.SelectedValuePath); if (v.Equals(v1) == true) { row.Add(BindingUtils.Eval(comboBoxItem, binding.DisplayPath)); break; } } break; default: row.Add(null); break; } } result.Add(row); } return(result); }