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
Feedback
https://aka.ms/ContentUserFeedback.
Bald verfügbar: Im Laufe des Jahres 2024 werden wir GitHub-Issues stufenweise als Feedbackmechanismus für Inhalte abbauen und durch ein neues Feedbacksystem ersetzen. Weitere Informationen finden Sie unterFeedback senden und anzeigen für