3

Trying to figure out how I can bind a text color to a label. I have done this previously on background colors using Xamarin.Forms.VisualElement.BackgroundColorProperty as my first parameter in the SetBinding method, as such:

ShowReadOverlay.SetBinding(Xamarin.Forms.VisualElement.BackgroundColorProperty, new Xamarin.Forms.Binding("BackgroundColor", Xamarin.Forms.BindingMode.Default, new XamarinMobile.Converters.GridCellBackgroundColorConverter(), null, null, null));

However, there is no Xamarin.Forms.VisualElement.TextColorProperty and I do know you can bind a text color in XAML via <Label TextColor={Binding BindingPropertyName}.. but unsure how to accomplish this in code only.

Here is what I tried, obviously it did not work because there is no Xamarin.Forms.VisualElement.TextColorProperty:

headline.SetBinding(Xamarin.Forms.VisualElement.TextColorProperty, new Xamarin.Forms.Binding("BackgroundColor", Xamarin.Forms.BindingMode.Default, new XamarinMobile.Converters.GridCellBackgroundColorConverter(), null, null, null));

Thanks.

2
  • if your element is Label, use Label.TextColorProperty Commented May 2, 2017 at 16:05
  • @Jason thanks! I think that worked! I'll check your answer if you want to make one. Commented May 2, 2017 at 16:08

1 Answer 1

4

Usually you can do something like (for a Label).

you should use

using Xamarin.Forms;

myLabel.SetProperty(Label.TextColorProperty, new Binding("BackgroundColor", BindingMode.Default, new GridCellBackgroundColorConverter()));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.