Hi,
I am kind of stuck in the different approaches to UI design in Silverlight, combined with the aspect of reusability. Assume the following simple example:
A base class ORGANISM has a NAME + AGE
The child class DOG has a FURCOLOR
The child class HUMAN has a JOB
Now I have a list of 30 ORGANISMs, some DOG, some HUMAN.
I can use a listBox to show all items (class names).
I want to create a "basic look" for ORGANISM (e.g. Name at the TOP)
If the data object is a DOG, I want to also list its furcolor.
If it is a HUMAN, I want to also list its job description.
I have tried DataTemplates, UserControls, and other stuff, but I seem to be stuck. There is no TargetType in Silverlight (or am I missing something) and this simple example seems to be very strangely complicated. Styles apply to visual elements only, not sure if they could be based on each other. But it also feels wrong...
My real example is more complex, but you get the idea. A base class has some properties I want to render, with child classes having some more I want to "add" without duplicating XAMl.
Any tips or hints in the right direction?
Chris
[EDIT] To clarify, the problem I have is not limited to lists. Another scenario is a details view, showing either a dog or a human. Most of the details view is identical, so I could use a UserControl with a red border to render Organism with a TextBlock bound to Name. Now below this textblock (but still inside the UserControl) there should be either a job or a furcolor block.
UserControl for ORGANISM
=================Fancy Border===================
Name: Horst
=================Fancy Border===================
BasedOn UserControl for HUMAN
=================Fancy Border===================
Name: Horst
Job: Software Designer
=================Fancy Border===================
BasedOn UserControl for Dog
=================Fancy Border===================
Name: Horst
FurColor: Brown
=================Fancy Border===================
Using all the above in the "parent control" and using visibility settings depending on Types just feels wrong, imagine 100 properties of Human, which then all would be hidden but existing in dog controls.