Editing multiple item types in the same control
-
Greetings, I'm trying to throw together a quick silverlight proof of concept, but I'm stuck on a slight issue. Let's say I have a base class (we'll call it Mammal) and two derived classes (dog and cat, respectively). I have an ObservableList<Mammal> that holds a whole bunch of cats and dogs. Now, I have a listbox defined like so: <ListBox x:name="lstMammals"> ... </ListBox> A little ways further down, I have a ContentControl (I'm not sure if this is the right control to use here) that contains a StackPanel with two user controls in it. One of the user controls handles dogs and the other cats. How do I do the binding in XAML in such a way that when I select an item in the listbox that the appropriate user control pops up for editing it? Or am I looking at the problem wrong? Thanks, Will
-
Greetings, I'm trying to throw together a quick silverlight proof of concept, but I'm stuck on a slight issue. Let's say I have a base class (we'll call it Mammal) and two derived classes (dog and cat, respectively). I have an ObservableList<Mammal> that holds a whole bunch of cats and dogs. Now, I have a listbox defined like so: <ListBox x:name="lstMammals"> ... </ListBox> A little ways further down, I have a ContentControl (I'm not sure if this is the right control to use here) that contains a StackPanel with two user controls in it. One of the user controls handles dogs and the other cats. How do I do the binding in XAML in such a way that when I select an item in the listbox that the appropriate user control pops up for editing it? Or am I looking at the problem wrong? Thanks, Will
It sounds like you want a master/detail scenario... Unfortunately, Silverlight doesn't support the rich, flexible data template bindings to do this like WPF has, so you'll need a little code. You can handle the listbox's selectionchanged event, and in your handler show a detail control appropriate for the type of the selected item. A search on "Silverlight master detail" yields several examples, like this one: Using User Controls to Implement Master/Detail Scenarios[^]
Mark Salsbery Microsoft MVP - Visual C++ :java: