Silverlight自定义控件继承问题

Silverlight自定义控件继承问题,silverlight,inheritance,user-controls,Silverlight,Inheritance,User Controls,所以,我在SL4中有以下控件 XAML: 这个类工作得很好,我可以实例化并使用它。但是,我有另一个控件,它是这个控件的子类: public class ArrowAnnotation : LineAnnotation { public ArrowAnnotation() : base() { // Some other init stuff } } 当我尝试在代码中实例化其中一个时,会出现以下异常: System.Windows.Markup.X

所以,我在SL4中有以下控件

XAML:

这个类工作得很好,我可以实例化并使用它。但是,我有另一个控件,它是这个控件的子类:

public class ArrowAnnotation : LineAnnotation
{

    public ArrowAnnotation() : base() 
    {
        // Some other init stuff
    }

} 
当我尝试在代码中实例化其中一个时,会出现以下异常:

System.Windows.Markup.XamlParseException: Failed to assign to property 'System.Windows.FrameworkElement.Loaded'. [Line: 5 Position: 47]
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at LineAnnotation.InitializeComponent()
   at LineAnnotation..ctor()
这不仅仅是加载的事件,它可以是任何事件处理程序,我得到同样的异常。这段代码恰好与WPF项目共享,而且效果很好。你知道这里有什么问题吗


编辑:我意识到ArrowAnnotation不需要是分部类,因为没有xaml。更改此选项没有任何区别。

您似乎无法执行此操作。您可以在codebehind中连接处理程序,也可以在子类中实现处理程序

public class ArrowAnnotation : LineAnnotation
{

    public ArrowAnnotation() : base() 
    {
        // Some other init stuff
    }

} 
System.Windows.Markup.XamlParseException: Failed to assign to property 'System.Windows.FrameworkElement.Loaded'. [Line: 5 Position: 47]
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at LineAnnotation.InitializeComponent()
   at LineAnnotation..ctor()