I have created user control MyUserControl. Now I want to create custom control MyCustomControl that derives from MyUserControl. MyCustomControl.cs code is following:
public class MyCustomControl : MyUserControl
{
public MyCustomControl()
{
this.DefaultStyleKey = typeof(MyCustomControl);
}
}
I have Themes/Generic.xaml file with the style
<Style TargetType="local:MyCustomControl">
...
</Style>
Instantiating MyCustomControl at runtime I get ArgumentException executing the line
this.DefaultStyleKey = typeof(MyCustomControl);
What am I missing?
Assigning a type that derives from
UserControltoDefaultStyleKeyis explicitly disallowed by throwing aArgumentException(why an ArgumentException and why no explanitory message is included only the SL team know).A
UserControlcannot be templated receiving instead its own associated Xaml. Thats the whole point ofUserControl. You need to convertMyUserControlinto a templatable control was well if you wish to inherit off it in manner you are attempting.