Customizing controls using xBehaviors
Starting with version 15 (as of the kits from the 05.05.2022) controls can be augmented by using the xBehavior
class.
This can be easily done by declaring a type inheriting from the xBehavior<T>
class defined in the TimeLine.Framework.Behaviors
namespace and implementing the OnAttached and OnDetaching abstrct methods.
The underlying control can be accessed through the AssociatedObject
property. Here's a small example of a xBehavior that turns the background color of all xButton controls to red:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TimeLine.Client.Controls;
using TimeLine.Framework.Behaviors;
using System.Windows.Media;
namespace CustomModule1
{
public class CustomControlBehavior : xBehavior<xButton>
{
protected override void OnAttached()
{
AssociatedObject.Background = Brushes.Red;
}
protected override void OnDetaching()
{
}
}
}
In order to apply a behavior for all controls automatically, you just need to add it to the TLAppContent.xml file in your customization, as follows:
<TLAppContent>
<WindowHandlingObjects>
<WHO ID="whoItem" DLL="CustomModule1.dll" Class="CustomModule1.wndItemCustom" Descr="" />
</WindowHandlingObjects>
<BusinessObjects>
<BO ID="busArt" DLL="CustomModule1.dll" Class="CustomModule1.busArtCustom" Descr="" SyncHybridType="" />
</BusinessObjects>
<Modules>
<Module ID="modItem" XAML="CustomModule1\wndItemCustom.xaml" WHO="whoItem" Title="Artikelstamm" AllowsDirectOpen="" Descr="" Uid="" />
</Modules>
<Reports />
<Behaviors>
<Behavior AttachedOn="TimeLine.Client.Controls.xButton" Dll="CustomModule1.dll" Class="CustomModule1.CustomControlBehavior" />
</Behaviors>
</TLAppContent>
After performing the steps described above each time a control is initialized that matches the AttachedOn
property on a declared behavior, a behavior instance will be instantiated and attached to that control automatically, calling the OnAttached
method, allowing you to write custom logic for controls in your customizations.
Last updated