expressappframework-devexpress-dot-expressapp-dot-frame-dot-getcontroller-1.md
Returns a specified Controller from the current Frame‘s Frame.Controllers collection.
Namespace : DevExpress.ExpressApp
Assembly : DevExpress.ExpressApp.v25.2.dll
NuGet Package : DevExpress.ExpressApp
public ControllerType GetController<ControllerType>()
where ControllerType : Controller
Public Function GetController(Of ControllerType As Controller) As ControllerType
| Name |
|---|
| ControllerType |
| Type | Description |
|---|---|
| ControllerType |
A specified Controller found in the current Frame‘s Frame.Controllers collection.
|
Use the GetController<ControllerType> method to access a particular Controller from the current Frame‘s Frame.Controllers collection. The ControllerType generic type argument specifies the required Controller type. In this argument, you can specify any class which is a descendant of the Controller class.
The code below demonstrates how to access the NewObjectViewController and add its NewObjectAction to the Quick Access Toolbar.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.SystemModule;
// ...
public class NewObjectActionController : WindowController {
protected override void OnActivated() {
base.OnActivated();
NewObjectViewController newObjectViewController = Window.GetController<NewObjectViewController>();
if(newObjectViewController != null) {
newObjectViewController.NewObjectAction.QuickAccess = true;
}
}
}
If there is no Controller of the specified type in the Frame.Controllers collection, this method returns the first Controller which is assignable to this type.
Important
To avoid possible null reference exceptions when accessing an existing Controller from your code, always ensure that the Frame.GetController<ControllerType> method result is not null when the XafApplication.OptimizedControllersCreation property is true.
The following code snippets (auto-collected from DevExpress Examples) contain references to the GetController<ControllerType>() method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
XAF-search-objects-using-complex-criterion/CS/Dennis.Search.Win/SearchObjectViewController.cs#L44
editor.ControlCreated += new EventHandler<EventArgs>(editor_ControlCreated);
RefreshController refreshController = Frame.GetController<RefreshController>();
if(refreshController != null) {
private void saSingleChoiceActionInvoker_Execute(object sender, SimpleActionExecuteEventArgs e) {
NewObjectViewController newObjectViewController = Frame.GetController<NewObjectViewController>();
if (newObjectViewController != null) {
private void Initialize() {
changeVariantController = Frame.GetController<ChangeVariantController>();
if(changeVariantController != null) {
if(View.CollectionSource is PropertyCollectionSource && ((PropertyCollectionSource)View.CollectionSource).MasterObjectType == typeof(ViewFilterContainer)) {
NewObjectViewController newObjectViewController = Frame.GetController<NewObjectViewController>();
if(newObjectViewController != null) {
protected override void OnFrameAssigned() {
NewObjectViewController newObjectViewController = Frame.GetController<NewObjectViewController>();
if (newObjectViewController != null) {
XAF-search-objects-using-complex-criterion/VB/Dennis.Search.Win/SearchObjectViewController.vb#L57
Dim refreshController As RefreshController = Frame.GetController(Of RefreshController)()
If refreshController IsNot Nothing Then
MyBase.OnActivated()
appearanceController = Frame.GetController(Of AppearanceController)()
MyBase.OnActivated()
Dim filterController = Frame.GetController(Of FilterController)()
If filterController IsNot Nothing Then
See Also