Back to Devexpress

XAF Templates

coderushforroslyn-403133-coding-assistance-code-templates-xaf-templates.md

latest16.6 KB
Original Source

XAF Templates

  • Jan 31, 2023
  • 8 minutes to read

This topic describes templates you can use when you implement Controllers and Actions in eXpressApp Framework ( XAF ).

Important

Visual Studio IntelliSense has priority over CodeRush templates. For information on how to prioritize a CodeRush template over Visual Studio IntelliSense , refer to the following topic section: Expand a Template Instead of Visual Studio IntelliSense.

XAF Custom Controllers

ViewController

Template: xcv

csharp
public class MyViewController : ViewController
{
    public MyViewController() : base()
    {
        // Target required Views (use the TargetXXX properties) and create their Actions.

    }
    protected override void OnActivated()
    {
        base.OnActivated();
        // Perform various tasks depending on the target View.
    }
    protected override void OnDeactivated()
    {
        // Unsubscribe from previously subscribed events and release other references and resources.
        base.OnDeactivated();
    }
    protected override void OnViewControlsCreated()
    {
        base.OnViewControlsCreated();
        // Access and customize the target View control.
    }
}
vb
Public Class MyViewController
    Inherits ViewController
    Public Sub New()
        MyBase.New()
        ' Target required Views (use the TargetXXX properties) and create their Actions.

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        ' Perform various tasks depending on the target View.
    End Sub
    Protected Overrides Sub OnDeactivated()
        ' Unsubscribe from previously subscribed events and release other references and resources.
        MyBase.OnDeactivated()
    End Sub
    Protected Overrides Sub OnViewControlsCreated()
        MyBase.OnViewControlsCreated()
        ' Access and customize the target View control.
    End Sub
End Class

WindowController

Template: xcw

csharp
public class MyWindowController : WindowController
{
    public MyWindowController() : base()
    {
        // Target required Windows (use the TargetXXX properties) and create their Actions.

    }
    protected override void OnActivated()
    {
        base.OnActivated();
        // Perform various tasks depending on the target Window.
    }
    protected override void OnDeactivated()
    {
        // Unsubscribe from previously subscribed events and release other references and resources.
        base.OnDeactivated();
    }
}
vb
Public Class MyWindowController
    Inherits WindowController
    Public Sub New()
        MyBase.New()
        ' Target required Windows (use the TargetXXX properties) and create their Actions.

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        ' Perform various tasks depending on the target Window.
    End Sub
    Protected Overrides Sub OnDeactivated()
        ' Unsubscribe from previously subscribed events and release other references and resources.
        MyBase.OnDeactivated()
    End Sub
End Class

ObjectViewController for DetailView

Template: xcvod

csharp
public class MyDetailViewController : ObjectViewController<DetailView, BusinessObject>
{
    public MyDetailViewController() : base()
    {
        // Target required Views (use the TargetXXX properties) and create their Actions.

    }
    protected override void OnActivated()
    {
        base.OnActivated();
        // Perform various tasks depending on the target View.
    }
    protected override void OnDeactivated()
    {
        // Unsubscribe from previously subscribed events and release other references and resources.
        base.OnDeactivated();
    }
    protected override void OnViewControlsCreated()
    {
        base.OnViewControlsCreated();
        // Access and customize the target View control.
    }
}
vb
Public Class MyDetailViewController
    Inherits ObjectViewController(Of DetailView, BusinessObject)
    Public Sub New()
        MyBase.New()
        ' Target required Views (use the TargetXXX properties) and create their Actions.

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        ' Perform various tasks depending on the target View.
    End Sub
    Protected Overrides Sub OnDeactivated()
        ' Unsubscribe from previously subscribed events and release other references and resources.
        MyBase.OnDeactivated()
    End Sub
    Protected Overrides Sub OnViewControlsCreated()
        MyBase.OnViewControlsCreated()
        ' Access and customize the target View control.
    End Sub
End Class

ObjectViewController for ListView

Template: xcvol

csharp
public class MyListViewController : ObjectViewController<ListView, BusinessObject>
{
    public MyListViewController() : base()
    {
        // Target required Views (use the TargetXXX properties) and create their Actions.

    }
    protected override void OnActivated()
    {
        base.OnActivated();
        // Perform various tasks depending on the target View.
    }
    protected override void OnDeactivated()
    {
        // Unsubscribe from previously subscribed events and release other references and resources.
        base.OnDeactivated();
    }
    protected override void OnViewControlsCreated()
    {
        base.OnViewControlsCreated();
        // Access and customize the target View control.
    }
}
vb
Public Class MyListViewController
    Inherits ObjectViewController(Of ListView, BusinessObject)
    Public Sub New()
        MyBase.New()
        ' Target required Views (use the TargetXXX properties) and create their Actions.

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        ' Perform various tasks depending on the target View.
    End Sub
    Protected Overrides Sub OnDeactivated()
        ' Unsubscribe from previously subscribed events and release other references and resources.
        MyBase.OnDeactivated()
    End Sub
    Protected Overrides Sub OnViewControlsCreated()
        MyBase.OnViewControlsCreated()
        ' Access and customize the target View control.
    End Sub
End Class

ViewController for DetailView

Template: xcvd

csharp
public class MyDetailViewController : ViewController<DetailView>
{
    public MyDetailViewController() : base()
    {
        // Target required Views (use the TargetXXX properties) and create their Actions.

    }
    protected override void OnActivated()
    {
        base.OnActivated();
        // Perform various tasks depending on the target View.
    }
    protected override void OnDeactivated()
    {
        // Unsubscribe from previously subscribed events and release other references and resources.
        base.OnDeactivated();
    }
    protected override void OnViewControlsCreated()
    {
        base.OnViewControlsCreated();
        // Access and customize the target View control.
    }
}
vb
Public Class MyDetailViewController
    Inherits ViewController(Of DetailView)
    Public Sub New()
        MyBase.New()
        ' Target required Views (use the TargetXXX properties) and create their Actions.

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        ' Perform various tasks depending on the target View.
    End Sub
    Protected Overrides Sub OnDeactivated()
        ' Unsubscribe from previously subscribed events and release other references and resources.
        MyBase.OnDeactivated()
    End Sub
    Protected Overrides Sub OnViewControlsCreated()
        MyBase.OnViewControlsCreated()
        ' Access and customize the target View control.
    End Sub
End Class

ViewController for ListView

Template: xcvl

csharp
public class MyListViewController : ViewController<ListView>
{
    public MyListViewController() : base()
    {
        // Target required Views (use the TargetXXX properties) and create their Actions.

    }
    protected override void OnActivated()
    {
        base.OnActivated();
        // Perform various tasks depending on the target View.
    }
    protected override void OnDeactivated()
    {
        // Unsubscribe from previously subscribed events and release other references and resources.
        base.OnDeactivated();
    }
    protected override void OnViewControlsCreated()
    {
        base.OnViewControlsCreated();
        // Access and customize the target View control.
    }
}
vb
Public Class MyListViewController
    Inherits ViewController(Of ListView)
    Public Sub New()
        MyBase.New()
        ' Target required Views (use the TargetXXX properties) and create their Actions.

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        ' Perform various tasks depending on the target View.
    End Sub
    Protected Overrides Sub OnDeactivated()
        ' Unsubscribe from previously subscribed events and release other references and resources.
        MyBase.OnDeactivated()
    End Sub
    Protected Overrides Sub OnViewControlsCreated()
        MyBase.OnViewControlsCreated()
        ' Access and customize the target View control.
    End Sub
End Class

XAF Actions

XAF templates that create Actions are available when the caret is inside a custom controller’s method.

SimpleAction

Template: xas

csharp
public class MyViewController : ViewController
{
    SimpleAction action;
    public MyViewController() : base()
    {
        // Target required Views (use the TargetXXX properties) and create their Actions.
        action = new SimpleAction(this, "MyAction", "View");
        action.Execute += action_Execute;

    }
    private void action_Execute(object sender, SimpleActionExecuteEventArgs e)
    {
        // Execute your business logic (https://docs.devexpress.com/eXpressAppFramework/112737/).
    }
    //...
}
vb
Public Class MyViewController
    Inherits ViewController
    Private action As SimpleAction
    Public Sub New()
        MyBase.New()
        ' Target required Views (use the TargetXXX properties) and create their Actions.
        action = New SimpleAction(Me, "MyAction", "View")
        AddHandler action.Execute, AddressOf action_Execute

    End Sub
    Private Sub action_Execute(ByVal sender As Object, ByVal e As SimpleActionExecuteEventArgs)
         ' Execute your business logic (https://docs.devexpress.com/eXpressAppFramework/112737/).
        End Sub
    End Sub
End Class

SingleChoiceAction

Template: xac

csharp
public class MyViewController : ViewController
{
    SingleChoiceAction action;
    public MyViewController() : base()
    {
        // Target required Views (use the TargetXXX properties) and create their Actions.
        action = new SingleChoiceAction(this, "MyAction", "View");
        action.ItemType = SingleChoiceActionItemType.ItemIsOperation;
        action.Execute += action_Execute;
        // Create some items
        //action.Items.Add(new ChoiceActionItem("MyItem1", "My Item 1", 1));     
    }
    private void action_Execute(object sender, SingleChoiceActionExecuteEventArgs e)
    {
        var itemData = e.SelectedChoiceActionItem.Data;
        // Execute your business logic (https://docs.devexpress.com/eXpressAppFramework/112738/).
    }
    //...
}
vb
Public Class MyViewController
    Inherits ViewController
    Private action As SingleChoiceAction
    Public Sub New()
        MyBase.New()
        ' Target required Views (use the TargetXXX properties) and create their Actions.
        action = New SingleChoiceAction(Me, "MyAction", "View")
        action.ItemType = SingleChoiceActionItemType.ItemIsOperation
        AddHandler action.Execute, AddressOf action_Execute
        ' Create some items
        'action.Items.Add(New ChoiceActionItem("MyItem1", "My Item 1", 1))     
    End Sub
    Private Sub action_Execute(ByVal sender As Object, ByVal e As SingleChoiceActionExecuteEventArgs)
        Dim itemData = e.SelectedChoiceActionItem.Data
        ' Execute your business logic (https://docs.devexpress.com/eXpressAppFramework/112738/).
    End Sub
End Class

ParametrizedAction

Template: xap

csharp
public class MyViewController : ViewController
{
    ParametrizedAction action;
    public MyViewController() : base()
    {
        // Target required Views (use the TargetXXX properties) and create their Actions.
        action = new ParametrizedAction(this, "MyAction", "View", typeof(string));
        action.Execute += action_Execute;

    }
    private void action_Execute(object sender, ParametrizedActionExecuteEventArgs e)
    {
        var parameterValue = (string)e.ParameterCurrentValue;
        // Execute your business logic (https://docs.devexpress.com/eXpressAppFramework/112724/).
    }
    //...
}
vb
Public Class MyViewController
    Inherits ViewController
    Private action As ParametrizedAction
    Public Sub New()
        MyBase.New()
        ' Target required Views (use the TargetXXX properties) and create their Actions.
        action = New ParametrizedAction(Me, "MyAction", "View", GetType(string))
        AddHandler action.Execute, AddressOf action_Execute

    End Sub
    Private Sub action_Execute(ByVal sender As Object, ByVal e As ParametrizedActionExecuteEventArgs)
        Dim parameterValue = CType(e.ParameterCurrentValue, string)
        ' Execute your business logic (https://docs.devexpress.com/eXpressAppFramework/112724/).
    End Sub
End Class

PopupWindowShowAction

Template: xapw

csharp
public class MyViewController : ViewController
{
    PopupWindowShowAction action;
    public MyViewController() : base()
    {
        // Target required Views (use the TargetXXX properties) and create their Actions.
        action = new PopupWindowShowAction(this, "MyAction", "View");
        action.Execute += action_Execute;
        action.CustomizePopupWindowParams += action_CustomizePopupWindowParams;

    }
    private void action_Execute(object sender, PopupWindowShowActionExecuteEventArgs e)
    {
        var selectedPopupWindowObjects = e.PopupWindowViewSelectedObjects;
        var selectedSourceViewObjects = e.SelectedObjects;
        // Execute your business logic (https://docs.devexpress.com/eXpressAppFramework/112723/).
    }
    private void action_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e)
    {
        // Set the e.View parameter to a newly created view (https://docs.devexpress.com/eXpressAppFramework/112723/).
    }
    //...
}
vb
Public Class MyViewController
    Inherits ViewController
    Private action As PopupWindowShowAction
    Public Sub New()
        MyBase.New()
        ' Target required Views (use the TargetXXX properties) and create their Actions.
        action = New PopupWindowShowAction(Me, "MyAction", "View")
        AddHandler action.Execute, AddressOf action_Execute
        AddHandler action.CustomizePopupWindowParams, AddressOf action_CustomizePopupWindowParams

    End Sub
    Private Sub action_Execute(ByVal sender As Object, ByVal e As PopupWindowShowActionExecuteEventArgs)
        Dim selectedPopupWindowObjects = e.PopupWindowViewSelectedObjects
        Dim selectedSourceViewObjects = e.SelectedObjects
        ' Execute your business logic (https://docs.devexpress.com/eXpressAppFramework/112723/).
    End Sub
    Private Sub action_CustomizePopupWindowParams(ByVal sender As Object, ByVal e As CustomizePopupWindowParamsEventArgs)
        ' Set the e.View parameter to a newly created view (https://docs.devexpress.com/eXpressAppFramework/112723/).
    End Sub
End Class

See Also

XPO Templates

Members Declaration

Custom Template Creation