【发布时间】:2011-12-05 16:00:35
【问题描述】:
所以,我在 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>
代码隐藏:
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。改变这一点没有任何区别。
【问题讨论】:
标签: silverlight inheritance user-controls