I have create a generic class that defines my main views:
public abstract class MainView<T, U> : UserControl, IMainView
where T : ControllerMainView<U>
where U : class
{
...
}
And I am using this to create a MainView of my Jobs
public partial class UserControlMainViewJobs : MainView<ControllerJobs, Job>
{
...
}
For this to work, ControllerJobs obviously needs to be a derivative of ControllerMain view, which it is.
public class ControllerJobs : ControllerMainView<Job>
{
...
}
Also, all classes have empty constructors, that the designer can use.
Still I can not open UserControlMainViewJobs in the Designer. Error Message is:
GenericArguments[0], 'FM.Auftragsverwaltung.Controller.ControllerJobs', on 'FM.Auftragsverwaltung.View.MainViews.MainView`2[T,U]' violates the constraint of type parameter 'T'.
Which makes no sense. But this seems to be general problem with generic user controls. Searching on StackOverFlow gave me this (and variations of it):
They suggest to create a static "intermediate class" to have a class that derives from MainView but is not deriving from a generic class.
So I create
public class MainViewJobsStatic : MainView<ControllerJobs, Job>
{
...
}
and then changed my UserControlMainViewJobs to
public partial class UserControlMainViewJobs : MainViewJobsStatic
{
...
}
Weirdly enough I still get the same error. Which makes me actually kind of happy since I find this workaround very frustrating.
Does anyone have an idea how to use the designer on a class that derives from a generic class?
* EDIT * Definition of ControllerMainView
public abstract class ControllerMainView<T> where T : class
{
...
}