【发布时间】:2014-11-18 18:48:01
【问题描述】:
我正在制作自己的图形控件,它有数字列表
public class Figure
{
public virtual void Render(Graph graph, GDI.Graphics graphics) { }
}
// was nested before, that's why here is @jnovo answer
public class Line : Figure { ... }
public class Plot : Figure { ... }
... // more figures
[ContentProperty("Figures")] // this doesn't help
public class Graph : FrameworkElement
{
public IList<Figure> Figures { get; set; }
}
而且我在 xaml 中定义它时遇到问题:
<local:Graph>
<local:Graph.Figures>
<local:Line/> <!-- Property 'Figures' does not support values of type 'Line' -->
</local:Graph.Figures>
</local:Graph>
如何解决?
【问题讨论】:
-
将您的
IList<Figure>更改为List<Figure>,它现在可以工作了。 -
虽然您在更新问题之前确实遇到了
IList的问题,但这不是主要问题 - 实际上还没有发生。恕我直言,您的编辑过于激进,没有反映原始问题。因此,在未来,请在编辑中投入更多精力 - 至少解释原始问题 - 或提出新问题。不管怎样,我很高兴你把它解决了:)