TemplateContainerAttribute.BindingDirection 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取容器控件的绑定方向。
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,指示容器控件的绑定方向。 默认值为 OneWay。
示例
下面的代码示例演示如何创建命名 TemplatedFirstControl
的模板化控件并将其与名为 FirstTemplateContainer
的容器相关联。 这允许创建自定义控件,这些控件在未指定模板时显示服务器时间,并在指定模板时显示模板的内容。 该方法GetCustomAttribute确定BindingDirection该TemplateFirstControl
属性FirstTemplate
的属性。
此代码示例是为类提供的大型示例的 TemplateContainerAttribute 一部分。
// 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 字段,模板可以接受和公开属性值。 在后一方案中,数据绑定控件可以使用数据绑定语法自动使用 Bind
数据源的更新、删除和插入操作。
有关数据绑定的详细信息,请参阅 绑定到数据库 和数据 绑定表达式概述。