Click or drag to resize
CalculationWorks Logo
Using a Custom Column Behavior Class
Using a Custom Column Behavior Class

The example shows how to create and use a custom column behavior.

Create a custom column behavior item. Remark: decorationg properites with BcfProperty or BcfMandatory attribute will cause BCF Editor to support the property.

public class UiInfoBehavior : BcfColumnBehaviorItemBase {

    public string Name { get; set; }

    public string ToolTip { get; set; }

    public string GetName() {
        return string.IsNullOrEmpty(Name) ? Column.Name : Name;

Create a custom column behavior to add typed access to the custom column behavior item.

public class MyColumnBehavior : BcfColumnBehavior {

    protected internal MyColumnBehavior(IEnumerable<BcfColumnBehaviorItemBase> behaviorItems) : base(behaviorItems) {
        UiInfo = behaviorItems.OfType<UiInfoBehavior>().FirstOrDefault() ?? new UiInfoBehavior();

    public UiInfoBehavior UiInfo { get; private set; }

Create a custom column behavior factory to redirect column behavior creation to MyColumnBehavior.

public class MyColumnBehaviorFactory : BcfDataSetColumnBehaviorFactory {

    protected override BcfColumnBehavior CreateInstance(IEnumerable<BcfColumnBehaviorItemBase> behaviorItems) {
        return new MyColumnBehavior(behaviorItems);

With BCF Editor add UiInfoBehavior as column behavior items and MyColumnBehaviorFactory as dataset behavior item.

In code you can access MyColumnBehavior via:

var myColumnBehavior = (MyColumnBehavior)anyColumn.Behavior;
var columnToolTip = myColumnBehavior.UiInfo.ToolTip;
var columnUiName = myColumnBehavior.UiInfo.Name;
See Also