开发者

How to implement WPF Dynamic UI

开发者 https://www.devze.com 2023-01-09 23:44 出处:网络
I\'m developing a WPF applicaition to try and get a better understanding of what it\'s about and what it can do. I\'ve got a situation though which I\'m not sure how best to implement, where basically

I'm developing a WPF applicaition to try and get a better understanding of what it's about and what it can do. I've got a situation though which I'm not sure how best to implement, where basically my UI needs to change depending on user selection.

Essentially I wish to build up a set of 'ConditionRows', where the user specifies a 'Field' and 'Condition' and a 'Style' to use if that condition matches. I imagine the layout to be similar to that below.

alt text http://img63.imageshack.us/img63/1813/39321945.jpg

What I need to do is change what is displayed in the 'Control 1' (either a textbox, or 2 textboxes and a label, or nothing) and 'Control 2' (either a bound combobox, numeric up/down, colour p开发者_如何学Goicker). I'm not quite sure the best way to dynamically change these controls though and keep the code/xaml separation as much as possible.


If you are doing MVVM, you can make the child ViewModel for each control area a polymorphic property of the main ViewModel (i.e. IControlGroupViewModel, and a concrete ViewModel for each possible control grouping). Then you can then create a data template for each concrete type in a resource dictionary. If you bind the view to the polymorphic property, the correct datatemplate should be chosen at run time.

0

精彩评论

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