2
我正在从我们的Silverlight应用程序打印一组标签。构成数据的数据是从数据库中读取的,UI元素在运行中创建并添加到Canvas
进行布局。标签在网页上以网格布置,行数和列数由所使用的纸材确定。线条元素不出现在打印的第二页和后续页面
:
一切从线到“重拳出击”的元素(例如原价当一个项目在售)的加入除了做工精细这是生成行的代码:
var line = new Line { StrokeThickness = 2, Stroke = new SolidColorBrush(Colors.Black) };
line.X1 = 0;
line.SetBinding(Line.Y1Property, new Binding { ElementName = element.Name, Path = new PropertyPath("ActualHeight") });
line.Y2 = 0;
line.SetBinding(Line.X2Property, new Binding { ElementName = element.Name, Path = new PropertyPath("ActualWidth") });
// Insert the element straight after the element it's bound to
canvas.Children.Insert(canvas.Children.IndexOf(element) + 1, line);
line.SetValue(Canvas.TopProperty, element.GetValue(Canvas.TopProperty));
line.SetValue(Canvas.LeftProperty, element.GetValue(Canvas.LeftProperty));
// and make sure it's Z index is always higher
line.SetValue(Canvas.ZIndexProperty, (int)element.GetValue(Canvas.ZIndexProperty) + 1);
canvas
是用于显示标签的帆布element
是要伸出的元素(在这种情况下是原始价格)。
- 代码获取调用用于被印刷的所有标签。
- 绑定是一致的。
- 如果我使用硬编码值替换绑定,则该行会被绘制,因此它看起来是由绑定中的某些内容引起的。但是:
- “父”元素的
ActualHeight
和ActualWidth
对于每个标签都是相同的。 - 该行不是在其他地方打印出来的(我可以看到)。如果我在第一页停止输出,则不显示任何行。
- 其他一切正在出现并出现在正确的位置。
我错过了什么?