The task is as follows: depending on the value of Enum in DC.DocType, create various forms of WPF, and then work with them uniformly. Forms are not connected by an interface, and I am going to use only the basic members of WPF forms, such as ShowDialog ()
I am trying to do something like this, but then the conversion to the desired type fails. Explain, please, how to solve this problem?
object dlg; Type tp; switch (DC.DocType) { case QuestionnairesDocTypes.FormV: dlg = new CreateFormV1View(); tp = typeof(CreateFormV1View); break; case QuestionnairesDocTypes.FormL: dlg = new CreateFormL1View(); tp = typeof(CreateFormV1View); break; // ... } if ((dlg as tp).ShowDialog() == true) { // .... }