I am trying to create a Silverlight custom control that derives from System.Windows.Con开发者_运维百科trols.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
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?
精彩评论