Recently I was asked a question about the default styles for WPF ListBoxItems and how to change the Style for the a Selected ListBox Item. This article has the solution to both the queries.
When data is bound to a WPF List Box, the List Items gets generated automatically and it becomes a bit clumsy to apply any style on the individual items in the ListBox. In such scenarios, we can implement the ItemContainerStyle property. Once this property is set, the style applied is set for every item in the ListBox when it is created.
In the code shown below, I have explained how an ItemContainerStyle can be applied. I have created a WPF application and added the following class in it:
The XAML code shown below defines the ItemContainerStyle for the ListBox:
Now run the application and the following result will be displayed:
and move the mouse cursor over each ListBoxItem, the following result will be displayed
The ItemContainerStyle provides a mechanism for applying styles formatting on individual WPF ListBox items.
Tweet
1 comment:
The background property on mouse over does not work on Windows 8 (the background is still white, the default color of my theme)
Post a Comment