views:

24

answers:

1

Hey,

is there a way to have a WPF UserControl Class to be a class with a Template type? e.g.

public partial class MyControl : UserControl

should be:

public partial class MyControl<MyData> : UserControl

as I always get compile errors that MyControl than has no reference to InitializeComponents which is in the automatic generated part of the class. The problem is, that I can't tell in the xaml part of the class that the usercontrol is of type MyControl<MyData>. I even tried MyControl&lt;MyData&gt; ... :(

Ciao Ephraim

A: 

No, you can't declare a generic type in XAML. From http://social.msdn.microsoft.com/forums/en-US/wpf/thread/02ca0499-80af-4c56-bb80-f1185a619a9e:

Hello, you can use generic as long as you don’t use XAML. But unfortunately, if you want to use XAML to define your control, you can’t use generic…

You can create a control in XAML that inherits from a generic type by putting a x:TypeArguments attribute on the root tag, but the control itself must be concrete.

Quartermeister