I have a very simple question.
I have a ListView control and I want to know how to create an item with an icon on the left side. The items will be dynamically added in code in C# and not through XAML.
Image Sample: here
Something similar to above (excluding the Manage Records header). I managed to do the one above by creating grids dynamically (not using a ListView control) but I’m not sure on how to control the events (click, etc).
Thanks in advance. 🙂
Solution consists in overriding view item DataTemplate.
Then we have to set our PresentationModel as view’s DataContext in code behind this view:
As you can see from binding expression in XAML our presentation model should expose Items property (if you consider changing Items list in runtime, underlying collection must be ObservableCollection in order to ListView reacts on its changes):
In this solution I add existing PNG images to Properties.Resources class. Then icons has type Bitmap that is incompatible with Source property type, so we should convert it to BitmapSource with next converter:
On other hand you can use pack uri’s for storing icons instead of resources. Then your ViewData class will expose property of type Uri (instead of Bitmap). Then no converters are needed.