Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin how to bind a text color in code only

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.

like image 888
jdmdevdotnet Avatar asked Dec 02 '25 15:12

jdmdevdotnet


1 Answers

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()));
like image 151
Alessandro Caliaro Avatar answered Dec 04 '25 05:12

Alessandro Caliaro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!