开发者

How to exchange window content dynamically in WPF

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 gu开发者_开发百科ys 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


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}" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜