Binding Constructors
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.
Overloads
| Name | Description |
|---|---|
| Binding() |
Initializes a new instance of the Binding class. |
| Binding(String, BindingMode, IValueConverter, Object, String, Object) |
Initializes a new instance of the Binding class with the specified path, mode, converter, and source. |
Binding()
- Source:
- Binding.cs
- Source:
- Binding.cs
- Source:
- Binding.cs
- Source:
- Binding.cs
Initializes a new instance of the Binding class.
public:
Binding();
public Binding();
Public Sub New ()
Applies to
Binding(String, BindingMode, IValueConverter, Object, String, Object)
- Source:
- Binding.cs
- Source:
- Binding.cs
- Source:
- Binding.cs
- Source:
- Binding.cs
Initializes a new instance of the Binding class with the specified path, mode, converter, and source.
public Binding(string path, Microsoft.Maui.Controls.BindingMode mode = Microsoft.Maui.Controls.BindingMode.Default, Microsoft.Maui.Controls.IValueConverter converter = default, object converterParameter = default, string stringFormat = default, object source = default);
new Microsoft.Maui.Controls.Binding : string * Microsoft.Maui.Controls.BindingMode * Microsoft.Maui.Controls.IValueConverter * obj * string * obj -> Microsoft.Maui.Controls.Binding
Public Sub New (path As String, Optional mode As BindingMode = Microsoft.Maui.Controls.BindingMode.Default, Optional converter As IValueConverter = Nothing, Optional converterParameter As Object = Nothing, Optional stringFormat As String = Nothing, Optional source As Object = Nothing)
Parameters
- path
- String
The property path to bind to.
- mode
- BindingMode
The binding mode.
- converter
- IValueConverter
The value converter to use.
- converterParameter
- Object
The parameter to pass to the converter.
- stringFormat
- String
The string format to apply to the bound value.
- source
- Object
The source object for the binding.
Remarks
The following example shows how to set a binding to a property with a BindingMode and Converter:
public class PersonViewModel
{
public string Name { get; set; }
public string Company { get; set; }
}
public class ReverseConverter : IValueConverter
{
public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var s = value as string;
if (s == null)
return value;
return new string (s.Reverse ().ToArray ());
}
public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var s = value as string;
if (s == null)
return value;
return new string (s.Reverse ().ToArray ());
}
}
var label = new Label ();
PersonViewModel person;
label.BindingContext = person = new PersonViewModel { Name = "John Doe", Company= "Xamarin" };
label.SetBinding (Label.TextProperty, new Binding ("Name", mode: BindingMode.TwoWay, converter: new ReverseConverter ()));
Debug.WriteLine (label.Text); //prints "eoD nhoJ". ReverseConverter.Convert () is invoked in this case.
label.Text = "ooF";
Debug.WriteLine (person.Name); //prints "Foo". ReverseConverter.ConvertBack () is invoked in this case. The label Text change is propagated back as the BindingMode is TwoWay.