Change textColor in list view item programmaticall

2020-05-09 18:43发布

问题:

I want to do something like this:

 textLabel_inCell.TextColor = Color.Black;

but Visual Studio shows an error:

"textLabel_inCell doesn't exist in the current context!"

How can I change text color of listView item programmatically? Please help.... Thanks everyone!

回答1:

Yes, textLabel really doesn't exist as there is no single textLabel but rather many of them in the ListView.

In general this is done with data binding: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/xaml-basics/data-binding-basics#bindings-and-collections



回答2:

Simply, you can try this:

listView1.Items[0].SubItems[0].BackColor= Color.Violet;

Just do your own customization stuff for item index (0) as your need.

I hope this can help you bro ^_^

* More Clarifying * I meant this brothers,

and here you the code:

    private void button1_Click(object sender, EventArgs e)
    {
        listView1.Items[2].BackColor = Color.Red;
    }