Reputation: 5585
The Xamarin website has a section on View-To-View Binding, but the examples are in XAML, using the x:Reference
markup extension. How can I do the same thing in C# code?
Upvotes: 2
Views: 783
Reputation: 14750
x:Reference
is just setting a reference to an object as BindingContext
of another object.
This is basically:
myLabel.BindingContext = mySlider;
Upvotes: 2
Reputation: 1261
You can do it effectively the same way as the XAML example simply by setting your view's BindingContext to the other view.
Example:
var stepper = new Stepper();
var label = new Label {
BindingContext = stepper
};
label.SetBinding (Label.TextProperty, new Binding ("Value", stringFormat: "{0:F0}"));
Alternatively, you can set the Binding.Source:
var stepper = new Stepper();
var label = new Label();
label.SetBinding (Label.TextProperty, new Binding ("Value", stringFormat: "{0:F0}", source: stepper));
Upvotes: 3