I am not sure whether I understood your question, but typically, the best way to "associate a ListBox
item with an instance of a class" is to simply put the instance itself into the ListBox
. You only have to take care of what is displayed for the items. If you have a simple scenario, it might be sufficient to just override the class' ToString()
method. If you need a more sophisticated display, you should consider to create DataTemplates
for your classes.
If you do not have access to your Gesture classes, you should create a wrapper class for them (something like a ViewModel) and do the proposed adjustments for this wrapper class.
Moreover, you should make all those classes implement a common interface or base class, so that you can safely cast the currently selected item without adding an if
-statement for every type that might be in the ListBox
.