2

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

Tim Coulter
  • 8,705
  • 11
  • 64
  • 95
  • +1 because I had this same error message and for my purpose, making the class public is good enough, so this solved my problem. – Joshua Frank Nov 10 '10 at 21:21
  • +1 because I encountered this problem with an internal class that is used in my Application.Resources dictionary – Phil Mar 25 '12 at 21:57

1 Answers1

2

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?

iCollect.it Ltd
  • 92,391
  • 25
  • 181
  • 202
  • 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 Sep 10 '10 at 11:06