TemplateContainerAttribute.BindingDirection 属性
定义
获取容器控件的绑定方向。Gets the binding direction of the container control.
public:
property System::ComponentModel::BindingDirection BindingDirection { System::ComponentModel::BindingDirection get(); };
public System.ComponentModel.BindingDirection BindingDirection { get; }
member this.BindingDirection : System.ComponentModel.BindingDirection
Public ReadOnly Property BindingDirection As BindingDirection
属性值
一个 BindingDirection,指示容器控件的绑定方向。A BindingDirection indicating the container control's binding direction. 默认值为 OneWay。The default is OneWay.
示例
下面的代码示例演示如何创建名为的模板化控件 TemplatedFirstControl ,并将其与名为的容器相关联 FirstTemplateContainer 。The following code example demonstrates how to create a templated control named TemplatedFirstControl and associate it with a container named FirstTemplateContainer. 这允许创建自定义控件,这些控件在未指定模板时显示服务器时间,在指定模板时显示模板内容。This allows the creation of custom controls that display the server time when the template is not specified and the contents of the template when the template is specified. GetCustomAttribute方法确定 BindingDirection FirstTemplate 的属性的属性 TemplateFirstControl 。The GetCustomAttribute method determines the BindingDirection property of the FirstTemplate property of the TemplateFirstControl.
此代码示例是为类提供的更大示例的一部分 TemplateContainerAttribute 。This code example is part of a larger example provided for the TemplateContainerAttribute class.
// Get the class type for which to access metadata.
Type clsType = typeof(TemplatedFirstControl);
// Get the PropertyInfo object for FirstTemplate.
PropertyInfo pInfo = clsType.GetProperty("FirstTemplate");
// See if the TemplateContainer attribute is defined for this property.
bool isDef = Attribute.IsDefined(pInfo, typeof(TemplateContainerAttribute));
// Display the result if the attribute exists.
if (isDef)
{
TemplateContainerAttribute tca =
(TemplateContainerAttribute)Attribute.GetCustomAttribute(pInfo, typeof(TemplateContainerAttribute));
Response.Write("The binding direction is: " + tca.BindingDirection.ToString());
}
' Get the class type for which to access metadata.
Dim clsType As Type = GetType(VB_TemplatedFirstControl)
' Get the PropertyInfo object for FirstTemplate.
Dim pInfo As PropertyInfo = clsType.GetProperty("FirstTemplate")
' See if the TemplateContainer attribute is defined for this property.
Dim isDef As Boolean = Attribute.IsDefined(pInfo, GetType(TemplateContainerAttribute))
' Display the result if the attribute exists.
If isDef Then
Dim tca As TemplateContainerAttribute = CType(Attribute.GetCustomAttribute(pInfo, GetType(TemplateContainerAttribute)), TemplateContainerAttribute)
Response.Write("The binding direction is: " & tca.BindingDirection.ToString())
End If
注解
BindingDirection属性可以是 OneWay 字段,模板只能接受属性值或 TwoWay 字段,模板可以接受和公开属性值。The BindingDirection property can be either the OneWay field, where the template can accept only property values or the TwoWay field, where the template can accept and expose property values. 在后一种方案中,数据绑定控件可以使用数据绑定语法自动使用数据源的更新、删除和插入操作 Bind 。In the latter scenario, data-bound controls automatically can use the update, delete, and insert operations of a data source using the Bind data-binding syntax.
有关数据绑定的详细信息,请参阅 绑定到数据库 和 数据绑定表达式概述。For more information on data binding, see Binding to Databases and Data-Binding Expressions Overview.