Share via


TemplateBinding Class

Definition

Caution

Use Binding.Source=RelativeBindingSource.TemplatedParent

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

[System.Obsolete("Use Binding.Source=RelativeBindingSource.TemplatedParent")]
public sealed class TemplateBinding : Xamarin.Forms.BindingBase
type TemplateBinding = class
    inherit BindingBase
Inheritance
System.Object
TemplateBinding
Attributes
System.ObsoleteAttribute

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:

<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(DataTemplate, BindableProperty, String) static method to set template bindings in code.

Constructors

TemplateBinding()

Creates an empty template binding.

TemplateBinding(String, BindingMode, IValueConverter, Object, String)

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

Properties

Converter

Gets or sets the type converter to use to convert strings into instances of the bound property type.

ConverterParameter

Gets or sets a format string to use for displaying property values.

FallbackValue

Gets or sets the value to use instead of the default value for the property, if no specified value exists.

(Inherited from BindingBase)
Mode

Gets or sets the mode for this binding.

(Inherited from BindingBase)
Path

Gets or sets a string that identifies the property to which to bind.

StringFormat

Gets or sets the string format for this binding.

(Inherited from BindingBase)
TargetNullValue

Gets or sets the value to supply for a bound property when the target of the binding is null.

(Inherited from BindingBase)

Methods

ThrowIfApplied()

Throws an System.InvalidOperationException if the binding has been applied.

(Inherited from BindingBase)

Applies to