views:

75

answers:

1

I am trying to create a Silverlight custom control that derives from System.Windows.Controls.Control with visibility internal, but I am seeing problems when trying to apply a default style. Here's the simplest form of the class ...

internal class MyClass : Control
{
    public MyClass()
    {
        DefaultStyleKey = typeof(MyClass);
    }
}

... and here's a simple form of the default style in generic.xaml ...

<Style TargetType="controls:MyClass">
    <Setter Property="Margin" Value="10" />
</Style>

Although this control doesn't do anything useful, it is possible to create an instance of it, but only if its visibility is public. When the class is marked internal, the application raises the following runtime error:

Error: Unhandled Error in Silverlight Application 
Code: 4004    
Category: ParserError       
Message: No matching constructor found on type 'MyClass'.     
File:      
Line: 11     
Position: 40     

Can you please advise what I need to do to make an internal control class visible to the Xaml parser.

Thanks, Tim

A: 

Most late-binding scenarios use reflection and require the methods/members/properties to be public.

Why can you not leave it public in this instance?

Enough already
It's not a single class - it a whole namespace of classes that are not intended to be consumed by the end user of my library. The CLR has numerous internal classes, so I don't think I am trying to do something unreasonable, am I?
Tim Coulter