Skip to main content
.NET 8.0+

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

ViewController.TargetObjectType Property

Specifies a ViewController‘s target object type. The View Controller is activated only for Views that represent this type.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v24.2.dll

NuGet Package: DevExpress.ExpressApp

#Declaration

[TypeConverter(typeof(BusinessClassTypeConverter<object>))]
[DefaultValue(null)]
public Type TargetObjectType { get; set; }

#Property Value

Type Default Description
Type null

An object’s type.

#Remarks

View Controllers are activated for both Windows and Frames. However, you can specify the type of objects represented by a View to provide a View Controller activation. For this purpose, specify the TargetObjectType property in code or the Designer.

To make a single View Controller available in Views of different business object types simultaneously, set the TargetObjectType property in code to an interface or their base class type, which is implemented or inherited by all these business types respectively. Also, for the same task, you can specify several View identifiers using the ViewController.TargetViewId property.

Note

The TargetObjectType property affects only ViewController’s activation. Controller.FrameAssigned and other events that are irrelevant to the object type always fire.

The following example creates a List View and displays it via a PopupWindowShowAction.

using System;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
// ...
public class ShowListViewController : ViewController {
    public ShowListViewController() {
        PopupWindowShowAction showListViewAction = new PopupWindowShowAction(this, "ShowListView",
            PredefinedCategory.Edit);
        this.TargetObjectType = typeof(Note);
        showListViewAction.CustomizePopupWindowParams += ShowListViewAction_CustomizePopupWindowParams;
    }
    private void ShowListViewAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) {
        Type objectType = typeof(Person);
        e.View = Application.CreateListView(objectType, true);
    }
}

Alternatively, you can implement the generic ObjectViewController<ViewType, ObjectType> Controller instead of the ViewController and specify the View and object type for which this Controller should be activated in the ViewType and ObjectType generic parameters.

See Also