BindableObjectExtensions.SetBinding Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Crée et applique une liaison à une propriété.
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)
Paramètres
- self
- BindableObject
L’BindableObjectopérateur
- targetProperty
- BindableProperty
BindableProperty sur lequel définir une liaison.
- mode
- BindingMode
BindingMode pour la liaison. Ce paramètre est optionnel. La valeur par défaut est Default.
- converter
- IValueConverter
IValueConverter pour la liaison. Ce paramètre est optionnel. La valeur par défaut est null
.
- stringFormat
- String
Chaîne utilisée comme stringFormat pour la liaison. Ce paramètre est optionnel. La valeur par défaut est null
.
Remarques
L’exemple suivant montre comment utiliser la méthode d’extension pour définir une liaison.
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"
S’applique à
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