Silverlight自定义控件继承问题

3

那么,在SL4中我有以下控件...

XAML:

<Canvas x:Class="LineAnnotation"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Canvas.Left="0" Canvas.Top="0" Loaded="Canvas_Loaded"  >
</Canvas>

CodeBehind:

public partial class LineAnnotation : Canvas
    {


        public LineAnnotation()
        {
            InitializeComponent();

        }


        void Canvas_Loaded(object sender, RoutedEventArgs e)
        {
            this.Height = ((Canvas)this.Parent).Height;
            this.Width = ((Canvas)this.Parent).Width;
        }
    }

这个类运行良好,我可以实例化并使用它。然而,我有另一个控件是这个类的子类:

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()

不仅仅是Loaded事件,任何事件处理程序都有可能出现这种异常。这段代码还与一个WPF项目共享,并且在那里可以正常工作。有什么想法吗?

编辑:我意识到ArrowAnnotation不需要成为一个部分类,因为没有xaml。但更改这个也没有任何区别。

1个回答

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接