The following is a simplified example of what I'm really trying to do, but my question about it is the same.
Suppose I have two objects, Man and Woman, both of which have the same Properties (Age, Height and Weight), but they are two distinct objects. I cannot change that.
Now suppose that I have a WPF panel, made using the MVVM principle that shows the Age of a certain Man in a textbox. I use Text="{Binding Path=OnePerson.Age}" for that, where OnePerson is an object of the type Man defined in the viewmodel.
This works fine, but I want a similar page to display this information of a Woman. Ideally, I'd like to just use the same view and viewmodel as before. But this is tricky, because the databinding points to the Man-object OnePerson. I can change the databinding programmatically (as described in WPF Binding Programatically), but I can only do so from the view's codebehind. I'm not allowed to do that, because we're using the MVVM model.
I would like to make OnePerson refer to either a Man or Woman object, but I don't know a good way to do so. They are different types, so I can't just assign either a Man or Woman using an if statement. I could declare OnePerson as an object instead of as a type, but then I can't access the Age, Height and Weight properties so easily anymore. Or I could make an entirely different ViewModel, one of which declares OnePerson as a Man and the other as a Woman, and use the same View for both of them. I think that should work, but it seems a bit weird to have two viewmodels for a single view. And adding my own Person class and translating between that and either Man or Woman would probably just make the whole viewmodel considerably more complicated when I start adding functionality like adding a new Man/Woman or editing an existing one, to the point where I might as well copy-paste the Man view and viewmodel and change only the OnePerson object to a Woman.
My question is, is there a clean and simple way to use a single View and Viewmodel to display the information of either a Man or a Woman in this case. Or should I not bother and make seperate pages for these cases?
Hope this is clear enough.