I have read the docs and tried many samples but to be honest the samples look like a big jumbled mess and don’t seem to make much sense.
Can anyone recommend any easy to follow tutorials or docs on how to style a ListView control in XAML? (Without Expression Blend)
The two main common tricks to styling a ListView are to style the items and change the kind of container the listbox uses to lay the items out.
Styling an Item
This basically means setting the
ItemTemplatein xaml to something that knows how to dispay the thing that is the content of the listbox’sItemsSource, typically using bindings.For example, if you have an
ObservableCollection<Customer>bound to the listbox where customer is defined as:Then you might style the items with a data template as follows:
A basic example but you get the idea.
Changing how items are laid out
Essentially you might not want the default behaviour where items are listed vertically, so you can change the container control used inside the listbox to something more suitable using the
ItemsPanelproperty. If, for example you had an item template that looked like an item from the “large icons” view in Windows Explorer, then you might want the listbox to use aWrapPanelrather than aStackPanel(I’m pretty sure it’s aStackPanel):Again a basic example.
I wrote all this code from memory into StackOverflow so apologies if there are a few typos or mis-remembered bits in there.
HTH.