Description:
Hi
I can't open the designer for several of my view controllers because these controllers' base type is ObjectViewController<DetailView, Customer>, which is abstract.
How to show the designer for such controllers?
The designer must create an instance of type 'DevExpress.ExpressApp.ObjectViewController`2[[DevExpress.ExpressApp.DetailView, DevExpress.ExpressApp.v17.2, Version=17.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a],[MyName.MyNameSpace.Model.Customer, MyName.MyNameSpace.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' but it cannot because the type is declared as abstract.
Answer:
SYMPTOMS
XAF Controllers are technically descendants of the System.ComponentModel.Component class, primarily to be smoothly integrated with the Visual Studio design time features. The standard Component designer does not support generic classes due to a Visual Studio limitation: https://stackoverflow.com/questions/6877217/can-visual-studio-designer-show-classes-inheriting-generic-types
This is a Microsoft functionality and we cannot do much about it on our side. So, if you have a class like this, and try to double click it or use the Enter key for it in the Solution Explorer, you will receive this error, which is expected here:
Originally, generic View Controllers (ViewController<ViewType> and ObjectViewController<ViewType, ObjectType>) were specially designed for users who prefer to do everything manually and want to have a more elegant and compact code. Here is an example that also shows how to declare Actions in code:
C#public class ViewController1 : ViewController<ListView> {
public ViewController1() {
ParametrizedAction action = new ParametrizedAction(this, "Action1", PredefinedCategory.View, typeof(String));
action.Execute += ...
}
}
One of the main benefits is that you can avoid excessive casts to the View or target object types and use the helper View and ViewCurrentObject properties directly, because they will already be of the required specific type.
Refer to the Concepts > Extend Functionality > Define the Scope of Controllers and Actions article for more details.
RESOLUTION
To avoid the aforementioned error at design time for generic View Controllers, consider the following solutions:
For XAF v17.2.6+
We have removed the visual designer association from the base ViewController<V> and ObjectViewController<V, T> classes using the [System.ComponentModel.DesignerCategory("Code")] attribute. This should work fine in Visual Studio 2015, 2017 and newer versions. This does not work for Visual Studio 2013 and older versions and we decided not to investigate this further, because of the very low usage rate of these IDEs nowadays. If you wish, you can still use one of the solutions below for them.
For older versions:
1. If you do NOT need designers and like to continue using benefits of generic View Controllers, simply do NOT double click or press the Enter key for a file with a generic View Controller class in the Solution Explorer. Instead, use the F7 keystroke or select the "View Code" item from the context menu:
Alternatively, you can decorate your generic ViewController class with the [System.ComponentModel.DesignerCategory("Code")] attribute as per https://stackoverflow.com/questions/6256327/vs-2010-setting-non-gui-class-file-as-component
However, it may be difficult to distinguish such files unless you follow a spacial naming convention for them.
2. If you require design time support and like to define Actions and set up other properties visually, do NOT use generic View Controllers at all. For this, either inherit your controller from a non-generic base class (ViewController or ObjectViewController) and specify the TargetViewType, TargetObjectType and other properties in the constructor or visually. It is easy to avoid this manual code writing by using the default Item Template from the DevExpress Template Gallery:
3. If you need designers, but also like benefits of generic View Controllers, consider introducing a non-generic base class inherited from a generic one. Here is an example:
Of course, you can create more base generic classes for DetailView, DashboardView and others in accordance with your business requirements.
Hi Dennis,
I seemed to have broken my ViewController :)
A long time ago I created a ViewController via the template. I added the TargetViewType & TargetObjectType to the constructor.
With this I added some actions via the Designer.
At some point in the near past I changed it to ObjectViewController<V, T> but later found out I no longer have access to the Designer,
even though all of the Designer "code behind" files are still there, as well as the actions within (See Attached).
Since I want to use the Designer, I changed ObjectViewController<V, T> back to the original ViewController.
This change didn't work. I still don't get the Designer, double click brings up the Code view, right click does not give the Shift-F7 option to View Designer. So it looks like the solution is to create another controller and copy everything to it?
Hi Joe,
I've created a separate ticket on your behalf (T752004: No visual designer available for a ViewController class after changing the base type from the generic ObjectViewController<V, T> to ViewController). It has been placed in our processing queue and will be answered shortly.