Putting WPF Controls into canvas with Visuals
Posted
by Mikhail
on Stack Overflow
See other posts from Stack Overflow
or by Mikhail
Published on 2010-03-08T22:51:33Z
Indexed on
2010/03/09
8:36 UTC
Read the original article
Hit count: 969
I am writing a WPF chart and use Visuals for performance. The code looks like:
public class DrawingCanvas2 : Canvas
{
private List<Visual> _visuals = new List<Visual>();
private List<Visual> _hits = new List<Visual>();
protected override Visual GetVisualChild( int index ) { return _visuals[index]; }
protected override int VisualChildrenCount { get { return _visuals.Count; } }
public void AddVisual( Visual visual )
{
_visuals.Add( visual );
base.AddVisualChild( visual );
base.AddLogicalChild( visual );
}
}
Beside DrawingVisual
elements (line, text) I need a ComboBox
in the chart. So I tried this:
public DrawingCanvas2()
{
ComboBox box = new ComboBox();
AddVisual( box );
box.Width = 100;
box.Height = 30;
Canvas.SetLeft( box, 10 );
Canvas.SetTop( box, 10 );
}
but it does not work, there is no ComboBox displayed. What I am missing?
© Stack Overflow or respective owner