So, I have the following control in 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;
}
}
This class works fine, I can instantiate and use it. However, I have another control that subclasses this one:
public class ArrowAnnotation : LineAnnotation
{
public ArrowAnnotation() : base()
{
// Some other init stuff
}
}
When i try to instantiate one of these in my code, I get the following exception:
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()
It's not just the Loaded event, it can be any event handler, I get the same exception. This code happens to be shared with a WPF project and this works fine. any idea what the problem is here?
EDIT: I realized that ArrowAnnotation need not be a partial class as there is no xaml. changing this made no difference.
It appears that you cannot do this. You can either wire up the handlers in the codebehind or implement the handlers in the subclass.
http://forums.silverlight.net/t/148606.aspx/1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With