I have a WPF UserControl with a ListBox and ContentPanel. The ListBox is bound to a ObservableCollection that has apples and oranges in it.
What is considered the proper way to have it setup so if I select an apple I see an AppleEditor on the right and if I select an orange an OrangeEditor shows up in the content panel?
I would suggest using DataTemplating to create and apply the different editors. Depending on how different your ‘apples’ and ‘oranges’ are I would recommend using a DataTemplateSelector. Also, if they had something like a Type property you could also use DataTriggers to switch out the editors.
Lets set up a small sample with apples and oranges. They’ll have some shared properties, and a few different properties as well. And then we can create an ObservableCollection of the base IFruits to use in the UI.
Next, we can create DataTemplateSelector, that will just check the type of the Fruit and assign the correct DataTemplate.
Then in the UI, we can create the two templates for Apples and Oranges, and use the selector to determine which gets applied to our content.