BindingExtensions

Wisej.Web.Markup.BindingExtensions

Namespace: Wisej.Web.Markup

Assembly: Wisej.Framework (4.0.0.0)

Adds fluent markup extension methods to the Control class.

public class BindingExtensions

Methods

Bind<TComponent, TTargetProp, TSource>(component, targetProp, dataSource, sourceProp, formattingEnabled, updateMode, nullValue, formatString, formatProvider, parse, format)

Binds a specified property of a component to a property of a data source.

Parameter
Type
Description

TComponent

The type of the component, which must implement IBindableComponent.

TTargetProp

The type of the target property on the component.

TSource

The type of the data source.

component

The component to bind to.

targetProp

An expression representing the target property on the component.

dataSource

The data source to bind from.

sourceProp

The name of the property on the data source to bind to.

formattingEnabled

Indicates whether formatting is enabled. Default is false.

updateMode

Specifies when the data source is updated. Default is OnValidation.

nullValue

The value to be used when the data source value is null. Default is null.

formatString

The format string to apply. Default is an empty string.

formatProvider

An object that provides culture-specific formatting information. Default is null.

parse

A function to convert the data source value to the target property type. Default is null.

format

A function to convert the target property value to the data source type. Default is null.

Returns: TComponent. The component with the binding applied.

This method allows for complex data binding scenarios where custom parsing and formatting logic is required.


var component = new TextBox();
var dataSource = new { Value = 123 };
component.Bind(c => c.Text, dataSource, "Value", format: v => v.ToString());

Bind<TComponent, TSource>(component, targetProp, dataSource, sourceProp, formattingEnabled, updateMode, nullValue, formatString, formatProvider, parse, format)

Binds a specified property of a component to a data source property with optional formatting and conversion.

Parameter
Type
Description

TComponent

The type of the component implementing IBindableComponent.

TSource

The type of the data source.

component

The component to bind the property to.

targetProp

The name of the target property on the component.

dataSource

The data source to bind to.

sourceProp

The name of the property on the data source to bind to.

formattingEnabled

Indicates whether formatting is enabled. Default is false.

updateMode

Specifies when the data source is updated. Default is OnValidation.

nullValue

The value to use when the data source property is null. Default is null.

formatString

The format string to apply. Default is an empty string.

formatProvider

The format provider to use. Default is null.

parse

A function to convert the data source value to the target property type. Default is null.

format

A function to convert the target property value to the data source type. Default is null.

Returns: TComponent. The component with the binding applied.

This method is useful for simple data binding scenarios where the target property and data source property types are compatible.


var component = new TextBox();
component.Bind("Text", dataSource, "Name");

Bind<TComponent, TSource>(grid, columnIndex, dataSource, sourceProp, parse, format)

Binds a specified column of the DataGridView to a data source.

Parameter
Type
Description

TComponent

The type of the DataGridView component.

TSource

The type of the data source.

grid

The DataGridView to bind.

columnIndex

The index of the column to bind.

dataSource

The data source to bind to.

sourceProp

The property of the data source to bind to the column.

parse

Optional. A function to parse cell values. Default is null.

format

Optional. A function to format cell values. Default is null.

Returns: TComponent. The DataGridView with the specified column bound to the data source.

This method binds a column of the DataGridView to a specified property of the data source.


var grid = new DataGridView();
grid.Bind(0, dataSource, "PropertyName");

Bind<TComponent, TSource>(grid, columnIndex, dataSource, dataMember, sourceProp, parse, format)

Binds a specified column of the DataGridView to a data source with a data member.

Parameter
Type
Description

TComponent

The type of the DataGridView component.

TSource

The type of the data source.

grid

The DataGridView to bind.

columnIndex

The index of the column to bind.

dataSource

The data source to bind to.

dataMember

The data member within the data source to bind to.

sourceProp

The property of the data source to bind to the column.

parse

Optional. A function to parse cell values. Default is null.

format

Optional. A function to format cell values. Default is null.

Returns: TComponent. The DataGridView with the specified column bound to the data source.

This method binds a column of the DataGridView to a specified property of the data source, using a data member.


var grid = new DataGridView();
grid.Bind(0, dataSource, "DataMember", "PropertyName");

Bind<TComponent, TSource>(grid, columnName, dataSource, sourceProp, parse, format)

Binds a specified column of the DataGridView to a data source using the column name.

Parameter
Type
Description

TComponent

The type of the DataGridView component.

TSource

The type of the data source.

grid

The DataGridView to bind.

columnName

The name of the column to bind.

dataSource

The data source to bind to.

sourceProp

The property of the data source to bind to the column.

parse

Optional. A function to parse cell values. Default is null.

format

Optional. A function to format cell values. Default is null.

Returns: TComponent. The DataGridView with the specified column bound to the data source.

This method binds a column of the DataGridView to a specified property of the data source using the column name.


var grid = new DataGridView();
grid.Bind("ColumnName", dataSource, "PropertyName");

Bind<TComponent, TSource>(grid, columnName, dataSource, dataMember, sourceProp, parse, format)

Binds a specified column of the DataGridView to a data source with a data member using the column name.

Parameter
Type
Description

TComponent

The type of the DataGridView component.

TSource

The type of the data source.

grid

The DataGridView to bind.

columnName

The name of the column to bind.

dataSource

The data source to bind to.

dataMember

The data member within the data source to bind to.

sourceProp

The property of the data source to bind to the column.

parse

Optional. A function to parse cell values. Default is null.

format

Optional. A function to format cell values. Default is null.

Returns: TComponent. The DataGridView with the specified column bound to the data source.

This method binds a column of the DataGridView to a specified property of the data source, using a data member and the column name.


var grid = new DataGridView();
grid.Bind("ColumnName", dataSource, "DataMember", "PropertyName");

Bind<TComponent, TSource>(grid, column, dataSource, sourceProp, parse, format)

Binds a specified DataGridViewColumn to a data source.

Parameter
Type
Description

TComponent

The type of the DataGridView component.

TSource

The type of the data source.

grid

The DataGridView to bind.

column

The DataGridViewColumn to bind.

dataSource

The data source to bind to.

sourceProp

The property of the data source to bind to the column.

parse

Optional. A function to parse cell values. Default is null.

format

Optional. A function to format cell values. Default is null.

Returns: TComponent. The DataGridView with the specified column bound to the data source.

This method binds a DataGridViewColumn to a specified property of the data source.


var grid = new DataGridView();
var column = grid.Columns[0];
grid.Bind(column, dataSource, "PropertyName");

Bind<TComponent, TSource>(grid, column, dataSource, dataMember, sourceProp, parse, format)

Binds a specified DataGridViewColumn to a data source with a data member.

Parameter
Type
Description

TComponent

The type of the DataGridView component.

TSource

The type of the data source.

grid

The DataGridView to bind.

column

The DataGridViewColumn to bind.

dataSource

The data source to bind to.

dataMember

The data member within the data source to bind to.

sourceProp

The property of the data source to bind to the column.

parse

Optional. A function to parse cell values. Default is null.

format

Optional. A function to format cell values. Default is null.

Returns: TComponent. The DataGridView with the specified column bound to the data source.

This method binds a DataGridViewColumn to a specified property of the data source, using a data member.


var grid = new DataGridView();
var column = grid.Columns[0];
grid.Bind(column, dataSource, "DataMember", "PropertyName");

Bind<TComponent, TSource>(listView, columnName, dataSource, sourceProp)

Binds a data source to a specified column in a ListView.

Parameter
Type
Description

TComponent

The type of the ListView component.

TSource

The type of the data source.

listView

The ListView component to bind the data source to.

columnName

The name of the column to bind the data source to.

dataSource

The data source to bind.

sourceProp

The property of the data source to display in the column.

Returns: TComponent. The ListView component with the data source bound to the specified column.

This method binds a data source to a specified column in a ListView by setting the column's display property name and assigning the data source to the ListView.


var listView = new ListView();
listView.Bind("ColumnName", dataSource, "SourceProperty");

Throws:

  • ArgumentException Thrown when the specified column name does not exist in the ListView.

Bind<TComponent, TSource>(listView, columnName, dataSource, dataMember, sourceProp)

Binds a data source to a specified column in a ListView with a specified data member.

Parameter
Type
Description

TComponent

The type of the ListView component.

TSource

The type of the data source.

listView

The ListView component to bind the data source to.

columnName

The name of the column to bind the data source to.

dataSource

The data source to bind.

dataMember

The data member of the data source to bind.

sourceProp

The property of the data source to display in the column.

Returns: TComponent. The ListView component with the data source bound to the specified column and data member.

This method binds a data source to a specified column in a ListView by setting the column's display property name, assigning the data member, and then assigning the data source to the ListView.


var listView = new ListView();
listView.Bind("ColumnName", dataSource, "DataMember", "SourceProperty");

Throws:

  • ArgumentException Thrown when the specified column name does not exist in the ListView.

Bind<TComponent, TSource>(listView, column, dataSource, sourceProp)

Binds a data source to a specified column in a ListView.

Parameter
Type
Description

TComponent

The type of the ListView component.

TSource

The type of the data source.

listView

The ListView component to bind the data source to.

column

The column to bind the data source to.

dataSource

The data source to bind.

sourceProp

The property of the data source to display in the column.

Returns: TComponent. The ListView component with the data source bound to the specified column.

This method binds a data source to a specified column in a ListView by setting the column's display property name and assigning the data source to the ListView.


var listView = new ListView();
var column = new ColumnHeader();
listView.Bind(column, dataSource, "SourceProperty");

Throws:

Bind<TComponent, TSource>(listView, column, dataSource, dataMember, sourceProp)

Binds a data source to a specified column in a ListView with a specified data member.

Parameter
Type
Description

TComponent

The type of the ListView component.

TSource

The type of the data source.

listView

The ListView component to bind the data source to.

column

The column to bind the data source to.

dataSource

The data source to bind.

dataMember

The data member of the data source to bind.

sourceProp

The property of the data source to display in the column.

Returns: TComponent. The ListView component with the data source bound to the specified column and data member.

This method binds a data source to a specified column in a ListView by setting the column's display property name, assigning the data member, and then assigning the data source to the ListView.


var listView = new ListView();
var column = new ColumnHeader();
listView.Bind(column, dataSource, "DataMember", "SourceProperty");

Throws:

Last updated

Was this helpful?