Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have a WPF Control Class being a template class

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; ...

like image 643
Ephraim Avatar asked Mar 20 '26 09:03

Ephraim


1 Answers

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.

like image 192
Quartermeister Avatar answered Mar 23 '26 01:03

Quartermeister



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!