views:

34

answers:

1

Hey everybody!

I need help on developing a WPF UI. I'm new to WPF. So far I read many tutorials and decided to follow a MVVM design pattern.

What I want to accomplish might seem simple: There is a ComboBox at the beginning of a window. It's embedded in a Grid with two rows. Now I want the content of the second row to depend on the selection of the ComboBox. This second row is to take up about 3 quarter of the page. The Combobox doesn't offer too many choices. Preferably I'd like to exchange not just a label for instance but the whole content of that part of the window.

Hopefully you guys get the idea ...

This illustration might help:

 ______________
|Source: File  |
|--------------|
|      _______ |
|File:|C:\... ||
|     |_______||
|              |
|______________|


 __________________
|Source: Database  |
|------------------|
|      _________   |
|Host:|localhost|  |
|     |_________|  |
|      _________   |               
|Port:|1521|    |  |
|     |_________|  |
|__________________|

Maybe it's possible to define a Grid for each subpage and exchanged them dynamically depending on the ComboBox selection?

Thanks for the time and effort in advance Toby

+2  A: 

The first thing that comes to my mind:

If you populate your combobox in XAML, put corresponding controls to the Tag of combobox item. Then just bind contents of your second row to SelectedItem.Tag:

<ContentControl Grid.Row="1" Content="{Binding ElementName=comboBox1, Path=SelectedItem.Tag}" />
Kefir
Thank you very much for your fast and helpful answer!Anyways, out of curiosity: Is there also a way to do the same thing if I would want to populate the ComboBox from Code-Behind?
There are several ways to achieve this. You can set Tag property to some element configured in XAML, or show proper controls using code-behind, or write a ValueConverter which will set controls visibility based on the ComboBox selection, or use DataTrigger to display corresponding control.
Kefir