Here is what I want to do: I have a List<myCustomType>. Now I want to display that list on a canvas (or any other container for that matter). Every property from myCustomType (a few strings, an image, a list of strings) has a designed control one the canvas. Basically I want to bind each control on my canvas to one property on myCustomType. Then I want to have buttons on the canvas that allow me to cycle through the List<myCustomType> and updates all controls at the same time so that all controls always show the contents of a single list item.
I have been looking around, but couldn’t find anything that I could use as a starting point.
Is that easily achievable? Or do I have to code that from scratch?
Here is an example using MVVM.
My Customer model is very simple and looks like this:
Next we need a ViewModel which the MainWindow of the application will be bound to. It holds the Customers and has the methods for moving between the Customers with buttons. The CollectionView type supports current item tracking and is I suppose something like WinForms’s BindingSource:
Next we have the View. I am using Caliburn Micro to simplify hooking up actions to the buttons. Simply download it and add a reference to Caliburn.Micro.dll to your project:
We have a ListBox bound to the Customers property of MyViewModel, buttons where their Click event has been attached to the MoveSelection methods, and the Customer fields are bound to the Customers/ property, which is short for Customers.CurrentItem.
Assuming this is the MainWindow of the WPF app all we need to do next is set its DataContext to MyViewModel. This can be done by adding the following to its constructor in the code-behind:
Everything should be setup now so you can build and run the application. It will look something like this: