Advanced programming


Another concept of the WPF are so-called "routing events". You react to routing events with so-called "event handlers". However, event handlers only work in conjunction with code-behind files in Visual Studio, since XAML is compiled with the code-behind file. In iPlus, XAML designs are loaded at runtime. The connection to a business object or ACComponent is therefore only made via data context , which is automatically set for the VBVisual and VBDesign control elements by the iPlus framework. Event handlers must therefore be provided in the ACComponent as normal client-side methods with the ACMethodInteractionClient-Attribute class:

 

Alternatively, you can also define client-side scripting methods in the iPlus development environment.

Important: If you declare the method in a business object, you can use normal methods with the "ACMethodInfo" attribute class as event handler methods. This is possible because a business object can never exist as a proxy object in comparison to instances from the application projects. With these methods, the mandatory first parameter, for which the IACComponent reference is passed, is also omitted.

After you have defined the method, open the tool window and the properties window in the designer. In the properties window, switch to the events list by pressing the "Events" button (1):

 

Expand the method area in the tool window and use "Drag & Drop" to move your event handler method to the event to which you want to react with this method (2) . The example responds to the MouseLeftButtonUp event. If you also select the "OnlyOnDblClick" checkbox, your method is only called when you double-click.

Then switch to the XAML editor. The following code was generated:

 

An event handler named VBDelegateExtension was assigned to the event. VBDelegateExtension is a markup extension from the gip.core.layoutengine. VBDelegateExtension has the ability to make ACUrlCommand calls and thus to call the client-side method described above. In the example, the ACUrlCmd property was only set with a preceding exclamation mark and the method name. This is a relative call to the bound ACComponent (DataContext). The call can of course also be specified absolutely.

Setting the OnlyOnDblClick property in the properties window has the following effects in the XAML code:

 


When responding to events, it is sometimes necessary to find out more about who triggered the event. For this, the WPF provides the base class "RoutedEventArgs", which are forwarded during tunneling and bubbling.

To get RoutedEventArgs passed from the VBDelegateExtension, add a parameter to your event handling method. In the following example the method has the parameter "MouseEventArgs e" _

 

Because the method is declared in a business object, the first parameter IACComponent is omitted. For client-side methods, the signature would have two parameters:

public void MyMethodName(IACComponent acComponent, MouseEventArgs e)

To ensure that the RoutedEventArgs parameter is passed by the VBDelegateExtension when the ACUrlCommand is executed, click on the "PassEventArgs" checkbox in the properties window of the designer. In the XAML code, this is expressed as follows:

 


You can also react to events in styles using EventTrigger .Event triggers, however, cannot be used to call a method in the model (or ACComponent), but,like property triggers ,they can only be used to make the surface dynamic. It is primarily required for animations, which will be discussed in the following chapter