我想在以下位置添加图像MyCanvas
:
public class MyCanvas : Canvas
{
private VisualCollection children;
public MyCanvas()
{ this.children = new VisualCollection(this); }
public void AddVisual(Visual visual)
{ this.children.Add(visual); }
public void RemoveVisual(Visual visual)
{ this.children.Remove(visual); }
public void ClearVisuals()
{ this.children.Clear(); }
protected override int VisualChildrenCount
{
get
{ return this.children.Count; }
}
protected override Visual GetVisualChild(int index)
{ return this.children[index]; }
}
我试过:
my_canvas.Children.Add(my_image);
// or also
my_canvas.AddVisual(my_image);
但my_image
不会出现。有什么问题,我必须如何解决?谢谢。