Let WPF Management Class be a Template Class

Is there a way for the UserControl WPF class to be a class with a template type? eg.

public partial class MyControl : UserControl 

it should be:

 public partial class MyControl<MyData> : UserControl 

since I always get compilation errors MyControl , which has no reference to InitializeComponents , which is in the automatically generated part of the class. The problem is that I cannot say in the xaml part of the class that usercontrol is of type MyControl<MyData> . I even tried MyControl&lt;MyData&gt; ...

+2
c # class templates wpf user-controls
source share
1 answer

No, you cannot 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 the generic option as long as you are not using XAML. But unfortunately, if you want to use XAML to define your control, you cannot use the generic ...

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

+1
source share

All Articles