我正在使用我以编程方式绘制的图像填充网格。
现在,我想在Image的顶部绘制线条(水平和垂直)。将Image作为子项添加到网格后,我想绘制线条。我怎么能这样做?
var image = new System.Windows.Controls.Image
{
Source = DrawImage(products),
Width = options.OutputWidth,
Height = options.OutputHeight
};
var grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
grid.Children.Add(image);
答案 0 :(得分:-1)
图像类扩展了FrameworkElement,因此您可以扩展图像类并在OnRender(DrawingContext dc)方法上添加您的绘图逻辑。
public class CustomeImage:Image{
protected ovveride OnRender(DrawingContext dc){
dc.DrawLine(//line location and pen here)
}
}