Share via


TemplateBinding Class

Definition

Caution

Use Binding.Source=RelativeBindingSource.TemplatedParent

Binds a property in a control template to a templated parent property.

public ref class TemplateBinding sealed : Microsoft::Maui::Controls::BindingBase
[System.Obsolete("Use Binding.Source=RelativeBindingSource.TemplatedParent")]
public sealed class TemplateBinding : Microsoft.Maui.Controls.BindingBase
[<System.Obsolete("Use Binding.Source=RelativeBindingSource.TemplatedParent")>]
type TemplateBinding = class
    inherit BindingBase
Public NotInheritable Class TemplateBinding
Inherits BindingBase
Inheritance
TemplateBinding
Attributes

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

Name Description
TemplateBinding()

Creates a new TemplateBinding with default values.

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

Creates a new TemplateBinding with the specified path and optional parameters.

Properties

Name Description
Converter

Gets or sets the converter used to convert values between source and target.

ConverterParameter

Gets or sets the parameter passed to the converter.

FallbackValue

Gets or sets the value used when the binding cannot produce a source value (e.g. path not found, conversion failure).

(Inherited from BindingBase)
Mode

Gets or sets the mode for this binding.

(Inherited from BindingBase)
Path

Gets or sets the path to the property on the templated parent.

StringFormat

Gets or sets the string format applied to the bound value.

(Inherited from BindingBase)
TargetNullValue

Gets or sets the value to use when the binding successfully resolves the source path and the resulting source value is null.

(Inherited from BindingBase)

Methods

Name Description
ThrowIfApplied()

Throws InvalidOperationException if the binding has already been applied.

(Inherited from BindingBase)

Applies to