views:

101

answers:

1

I have an area on the left with selectable items, and depending on what type of item is selected, I want to show one of three or four different forms on the right.

It would be nice to make some type of control so the main form can be less of a mess.

What's the best pattern for this in WPF?

I'm a WPF newbie, and I've spent some time going in some obviously incorrect directions. Thanks!

+2  A: 

I would say, whenever possible Templates are the way to go in WPF. They define how controls or data is displayed in the UI. Using templates, it is possible to use any object (not only strings) as the content of a Button, for example. If you set the content of a Button to be an object of type MyType, WPF will look for a DataTemplate for MyType in the resources and use that one if it is found. If no DataTemplate is found, it will use the ToString() method of that object and display the result.

In your scenario, you could use a simple ContentControl for your details view on the right and define different DataTemplates for each item type. If not every item needs a different template (i.e. some types share the same template), you could implement a ContentTemplateSelector to determine the correct DataTemplate programmatically.

The Data Templating Overview gives a good introduction into that topic.

HTH, good luck!

gehho