コード例 #1
0
 protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
 {
     //return base.GenerateEditingElement(cell, dataItem);
     var bind = new Binding(LevelPath);
     bind.Converter = IndentConverter;
     var be = new BindingEvaluator(bind);
     be.DataContext = dataItem;
     var left = (double)be.Value + 16;
     var element = base.GenerateEditingElement(cell, dataItem);
     element.Margin = new Thickness(element.Margin.Left + left, element.Margin.Top, element.Margin.Right, element.Margin.Bottom);
     return element;
 }
コード例 #2
0
ファイル: ExportHelper.cs プロジェクト: eolandezhang/Diagram
 static void CreateCells(ISheet sheet, DataGridColumn col,
     IEnumerable source, int colIndex)
 {
     int rowIndex = 0;
     #region header
     var headerStyle = GetHeaderCellStyle(sheet.Workbook);
     var rowHeader = sheet.GetOrCreateRow(rowIndex++);
     var cellHeader = rowHeader.GetOrCreateCell(colIndex);
     cellHeader.SetCellValue(GetHeaderText(col.Header));
     cellHeader.SetCellType(CellType.String);
     cellHeader.CellStyle = headerStyle;
     #endregion
     var cellStyle = GetCellStyle(col, sheet);
     if (col is DataGridBoundColumn)
     {
         var c = (DataGridBoundColumn)col;
         var be = new BindingEvaluator(c.Binding);
         foreach (var obj in source)
         {
             IRow row = sheet.GetOrCreateRow(rowIndex++);
             ICell cell = row.GetOrCreateCell(colIndex);
             cell.CellStyle = cellStyle;
             be.DataContext = obj;
             cell.SetCellValue(be.Value);
         }
     }
     else if (col is System.Windows.Controls.DataGridComboBoxColumn)
     {
         var c = (System.Windows.Controls.DataGridComboBoxColumn)col;
         var be = new BindingEvaluator(c.SelectedValueBinding);
         var bValue = new BindingEvaluator(new Binding(c.SelectedValuePath));
         var bDisplay = new BindingEvaluator(new Binding(c.DisplayMemberPath));
         var itemSource = new Dictionary<object, object>();
         foreach (var i in c.ItemsSource)
         {
             bValue.DataContext = i;
             bDisplay.DataContext = i;
             var value = bValue.Value;
             if (value != null)
                 itemSource[value] = bDisplay.Value;
         }
         foreach (var obj in source)
         {
             IRow row = sheet.GetOrCreateRow(rowIndex++);
             ICell cell = row.GetOrCreateCell(colIndex);
             cell.CellStyle = cellStyle;
             be.DataContext = obj;
             var value = be.Value;
             if (itemSource.ContainsKey(value))
                 cell.SetCellValue(itemSource[value]);
             else
                 cell.SetCellValue(be.Value);
         }
     }
     else if (col is System.Windows.Controls.DataGridTemplateColumn)
     {
         var c = (DataGridTemplateColumn)col;
         var x = DataGridHelper.GetAttachedBinding(c);
         if (x == null) return;
         foreach (var obj in source)
         {
             var be = new BindingEvaluator(new Binding(x));
             be.DataContext = obj;
             IRow row = sheet.GetOrCreateRow(rowIndex++);
             ICell cell = row.GetOrCreateCell(colIndex);
             cell.CellStyle = cellStyle;
             cell.SetCellValue(be.Value);
         }
     }
     sheet.AutoSizeColumn(colIndex);
 }