locked
Changing font color of list box items RRS feed

  • Question

  • Hi, I've a listbox with name "List" and want to change the font color of all the items in this listbox to white.

    I used to name each item like, L1, L2, L3, L4 and then write the code like

    L1.Foreground = Brushes.white;, L2L1.Foreground = Brushes.white; , etc. .. a very bad code :D ,

     any ideas for better shorter code works on any list without renaming items ?!

    Sunday, September 20, 2015 2:07 PM

Answers

  • You could iterate through all items using a foreach loop:

    foreach (var item in List.Items.OfType<ListBoxItem>())
                {
                    item.Foreground = Brushes.White;
                }

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Marked as answer by MrBrilliant12 Sunday, September 20, 2015 4:18 PM
    Sunday, September 20, 2015 3:45 PM