TemplateContainerAttribute.BindingDirection Свойство

Определение

Возвращает направление привязки контейнерного элемента управления.

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

Объект BindingDirection, указывающий направление связывания контейнерного элемента управления. Значение по умолчанию — OneWay.

Примеры

В следующем примере кода показано, как создать шаблонный элемент управления с именем TemplatedFirstControl и связать его с контейнером с именем FirstTemplateContainer. Это позволяет создавать пользовательские элементы управления, отображающие время сервера, когда шаблон не указан и содержимое шаблона при указании шаблона. Метод GetCustomAttribute определяет BindingDirection свойство FirstTemplate свойства свойства TemplateFirstControl.

Этот пример кода является частью более крупного примера, предоставленного 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 привязки данных.

Дополнительные сведения о привязке данных см. в разделе "Привязка к базам данных " и "Выражения привязки данных".

Применяется к

См. также раздел