How to set Listbox alternate row background colour using Blend for Visual Studio

532 Views Asked by At

I know that I can set the alternating row colour of list box by defining Item control style like this one

https://stackoverflow.com/a/3567894/1241992

I want to know how can I set this using Blend for Visual Studio. When I am designing my layout in Blend, I do not want to edit code and define my styles that way. I want to visualize and create my styles and I am sure there must be some way of doing it but I cannot figure out how. Strange thing is even if I try to edit this already defined style, I can not create another trigger property which defines AlternationIndex via Blend.

1

There are 1 best solutions below

2
Emmanuel DURIN On

Afraz,

You can do at least part of it using Blend.

  1. In Blend, select the ListBox, right click : Edit Additional templates/ Edit generated item container(itemContainerStyle)/ Edit a copy. It will create most of the code for the style of the ListBoxItem, that is a line of a ListBox.

  2. You can actually create some triggers going to the Trigger tab in the left of the screen. We want a property trigger But the triggers can only be created on properties of the ListBoxItem properties.
    Only properties of the ListBoxItem can be source of the triggers in the ComboBox just under. So rest of the code to affect the background color of the ListBoxItem has to be done in code.

Regards