BindableObjectExtensions.SetBinding Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates and applies a binding to a property.
public static void SetBinding (this Microsoft.Maui.Controls.BindableObject self, Microsoft.Maui.Controls.BindableProperty targetProperty, string path, Microsoft.Maui.Controls.BindingMode mode = Microsoft.Maui.Controls.BindingMode.Default, Microsoft.Maui.Controls.IValueConverter converter = default, string stringFormat = default);
static member SetBinding : Microsoft.Maui.Controls.BindableObject * Microsoft.Maui.Controls.BindableProperty * string * Microsoft.Maui.Controls.BindingMode * Microsoft.Maui.Controls.IValueConverter * string -> unit
<Extension()>
Public Sub SetBinding (self As BindableObject, targetProperty As BindableProperty, path As String, Optional mode As BindingMode = Microsoft.Maui.Controls.BindingMode.Default, Optional converter As IValueConverter = Nothing, Optional stringFormat As String = Nothing)
Parameters
- self
- BindableObject
The BindableObject.
- targetProperty
- BindableProperty
The BindableProperty on which to set a binding.
- mode
- BindingMode
The BindingMode for the binding. This parameter is optional. Default is Default.
- converter
- IValueConverter
An IValueConverter for the binding. This parameter is optional. Default is null
.
- stringFormat
- String
A string used as stringFormat for the binding. This parameter is optional. Default is null
.
Remarks
The following example shows how to use the extension method to set a binding.
public class PersonViewModel
{
public string Name { get; set; }
public string Company { get; set; }
}
// ...
var vm = new PersonViewModel {
Name = "John Doe",
Company = "Xamarin"
}
var label = new Label ();
label.SetBinding (Label.TextProperty, "Name"); // "Name" is the property on the view model
label.BindingContext = vm;
Debug.WriteLine (label.Text); // prints "John Doe"
Applies to
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour