views:

11

answers:

1

Hi all,

I am creating a series of UserControls in silverlight, and they all need a hand full of the same functions, such as ShowControl(), ValidateInput() etc.

I created an interface and which then had an abstract class inherit from it. I then changed my UserControls to inherit from the abstract instead of directly from UserControl.

This all compiled fine, but when I go into the SilverLight App the controls dont show, the editor in VS2010 gives me an error saying it "Cannot create an instance of" my control.

What did I miss?

I have included below my code:

The interface:

public interface IMyControl
{
    Action<string> ValueAction { get; set; }
    void ShowControl(StackPanel parentControl, Action<string> response);
}

The abstract control:

public abstract class MyControl : UserControl, IMyControl
{
    public abstract Action<string> ValueAction { get; set; }
    public abstract void ShowControl(StackPanel parentControl, Action<string> response);
    protected abstract void SetupControl();
    protected abstract void ValidateInput();
}

Thanks for any help on this one.

A: 

You also need to show your XAML so we can see what you are trying to do. Remember that you cannot create an instance of an abstract class directly, so you cannot declare a MyControl in your XAML, you have to use one of the derivatives.

slugster