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
.NET MAUI
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기