is there a way to have a WPF UserControl Class to be a class with a Template type? eg
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<MyData>
...
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.