Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to access a a label control or any other control inside the list view,

eldeekeldeek Member ✭✭

Hi,
I want to get the simple code to access a a label named LblPrice that binding a price value inside a list view that named LvProducts.
I just need to change its color in a conditional value.
Thanks in advance

Best Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Accepted Answer
    Yes why not?
  • riricardoriricardo Member ✭✭
    Accepted Answer

    You can try to use behaviours as well.

    Link for the Xamarin Show

    You have to create a class of label behaviour and assing it to the label you want, then you put the validation you want on the class you've created. But i think it is easier to do it as @AlessandroCaliaro said. If you want I'll try to create an example for you tonight.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Accepted Answer

    you bind your Listview to an observableCollection

    mymodel has some properties.
    you can use these properties and bind them to your view
    you can also use Triggers or ValueConverter to change the view properties dependig by your model properties

Answers

  • eldeekeldeek Member ✭✭

    @AlessandroCaliaro said:
    You have to use Binding, not access the control

    I am binding the text but I need in the back end code to change the label color,
    Do you mean to bind the color also .?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Accepted Answer
    Yes why not?
  • eldeekeldeek Member ✭✭

    @AlessandroCaliaro said:
    Yes why not?

    I'll try this today,
    But how generally can change property in a label inside a listview from cs file, ?

  • riricardoriricardo Member ✭✭
    Accepted Answer

    You can try to use behaviours as well.

    Link for the Xamarin Show

    You have to create a class of label behaviour and assing it to the label you want, then you put the validation you want on the class you've created. But i think it is easier to do it as @AlessandroCaliaro said. If you want I'll try to create an example for you tonight.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Accepted Answer

    you bind your Listview to an observableCollection

    mymodel has some properties.
    you can use these properties and bind them to your view
    you can also use Triggers or ValueConverter to change the view properties dependig by your model properties

  • eldeekeldeek Member ✭✭

    @riricardo said:
    You can try to use behaviours as well.

    Link for the Xamarin Show

    You have to create a class of label behaviour and assing it to the label you want, then you put the validation you want on the class you've created. But i think it is easier to do it as @AlessandroCaliaro said. If you want I'll try to create an example for you tonight.

    Yes, Appreciate,

  • eldeekeldeek Member ✭✭

    @riricardo said:
    Here it goes, I hope it help you out.
    I've made in the mvvm pattern and made the validation to the double type.
    Remember to put the namespace of the bahavior you've added on the xaml file in order to use it.

    Thank you sir, I will see it tonight.
    Appreciate a lot. :)

Sign In or Register to comment.