jbyrd
jbyrd

Reputation: 5585

Xamarin.Forms MVVM - Is there a way to Unset a Binding?

Is there a way to programmatically unset a binding? Something like:

myLabel.UnsetBinding(Label.TextColorProperty);

Surely there's gotta be a way to do this?

Upvotes: 5

Views: 2436

Answers (2)

Rodrigo Elias
Rodrigo Elias

Reputation: 783

A Binding is attached to a BindableProperty, not a class.

You can just set the Property to anything else and the Binding will be gone;

myLabel.Text = String.Empty;

Note: The above (Keith's) is the correct answer.

Upvotes: 4

Keith Rome
Keith Rome

Reputation: 3228

You are looking for the RemoveBinding() method: https://developer.xamarin.com/api/member/Xamarin.Forms.BindableObject.RemoveBinding/p/Xamarin.Forms.BindableProperty/

For your example:

myLabel.RemoveBinding(Label.TextColorProperty);

Upvotes: 12

Related Questions