Infragistics 15.2 WorksheetImage.SetBoundsInTwips 编译错误

Infragistics 15.2 WorksheetImage.SetBoundsInTwips compilation error

我有以下代码

System.Drawing.Image logo = ... (getting logo)
WorksheetImage worksheetImage = new WorksheetImage(logo);
worksheetImage.PositioningMode = ShapePositioningMode.DontMoveOrSizeWithCells;

// Original code (works with Infragistics 13.1)
Rectangle imageRect = new Rectangle(100, 100, 10 * logo.Width, 10 * logo.Height);
worksheetImage.SetBoundsInTwips(worksheet, imageRect, true); // Breaks here

以下代码适用于 Infragistics 13.1 库。但是,迁移到 15.2 时,编译器报错:

The best overloaded method match for 'Infragistics.Documents.Excel.WorksheetImage.SetBoundsInTwips(Infragistics.Documents.Excel.Worksheet, System.Windows.Rect, bool)' has some invalid arguments

Argument 2: cannot convert from 'System.Drawing.Rectangle' to 'System.Windows.Rect'

所以基本上它说第二个参数应该是 System.Windows.Rect 而不是 System.Drawing.Rectangle 类型。信息here表明我传入的类型是正确的,但是编译器不同意。为什么会这样?

Infragistics WindowsForms Excel 引擎的 SetBoundsInTwips 方法确实使用 System.Drawing.Rect 作为其参数之一。但是 WPF implementation 使用 System.Windows.Rect。如果此调用未编译,那么您可能正在使用 WPF 库。请检查您项目的参考资料,看看他们是否使用 WPF 程序集 (InfragisticsWPF4.Documents.Excel.v15.2) 并将其替换为 WF 程序集 (Infragistics4.Documents.Excel.v15.2).

因此问题已经解决 - 显然 Infragistics 15.2 中 WPF 中的方法 SetBoundsInTwips 将 Rect 与 13.1 中的 Rectangle 相对,因此将 Rectangle 更改为 Rect 就完成了这项工作。