Change color of label if value of another is >0???

Boco91Boco91 Member

Hello I am new to xamarin, i want to know how to change color of label if the value is higher than zero?

If case 1 value of label is higher than zero then change color of label to red.
if case 2 value of label is zero dont change color.

Can somebody help me?
Thanks

Tagged:

Answers

  • LeoOsvaldLeoOsvald ✭✭ Member ✭✭

    First you must name your label:

    then, in code behind do something like this

    if(variable > 0)
    {
    MyLabel.BackgroundColor = Xamarin.Forms.Color.Red;
    }

  • JamesLaveryJamesLavery ✭✭✭✭✭ GBBeta, University ✭✭✭✭✭
    This is using code behind. For Forms it's better to use the MVVM design pattern - so you would bind the Color property of the label to a property in the ViewModel. The getter of the ViewModel then returns the appropriate Color depending on the underlying value.
Sign In or Register to comment.