3

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.

0

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.