Xamarin.Forms Guides | Samples

Xamarin.Forms.TemplateBinding Class

Binds a template property to the parent of the view that owns a ControlTemplate.

See Also: TemplateBinding

Syntax

public class TemplateBinding : BindingBase

Remarks

Control templates provide reusable styling and functionality for common UI elements in an application. They do this by providing a common set of properties that bind to the parents of the View that owns the View to which the control template is bound.

Application developers can assign these properties through XAML, as in the following example:

XAML Example

<ControlTemplate x:Key="LoginTemplate">
  <StackLayout VerticalOptions="CenterAndExpand" Spacing="20" Padding="20">
    <Entry Text="{TemplateBinding Username}" Placeholder="Username" />
    <Entry Text="{TemplateBinding Password}" Placeholder="Password" />
    <Button Command="{TemplateBinding Command}" Text="Click Here To Log In" />
  </StackLayout>
</ControlTemplate>

Additionally, application developers can use the SetBinding static method to set template bindings in code.

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 2.0.0.0

The members of Xamarin.Forms.TemplateBinding are listed below.

See Also: BindingBase

Public Constructors

Creates an empty template binding.
Creates a new TemplateBinding with the specified values. Must be non-empty and non-null.

Public Properties

ConverterIValueConverter. Gets or sets the type converter to use to convert strings into instances of the bound property type.
ConverterParameterObject. Gets or sets a format string to use for displaying property values.
PathString. Gets or sets a string that identifies the property to which to bind.