public class VisualCue : FrameworkElement
{
public List<Indicator> Indicators { get; set; }
public VisualCue()
{
this.Indicators = new List<Indicator>();
}
protected override int VisualChildrenCount
{
get { return this.Indicators.Count; }
}
protected override Visual GetVisualChild(int index)
{
return this.Indicators[index];
}
}
public class Indicator : FrameworkElement
{
protected override void OnRender(DrawingContext context)
{
context.DrawEllipse(Brushes.Red,
new Pen(Brushes.Black, 2), new Point(0, 0), 10, 10);
base.OnRender(context);
}
}
在 XAML 中:
<local:VisualCue x:Name="visualCue">
<local:VisualCue.Indicators>
<local:Indicator />
</local:VisualCue.Indicators>
</local:VisualCue>
但指标没有被绘制。我错过了什么?