c# - Different input forms depending on property in MVVM -


so i've got wpf mvvm application (as example) stores different types of customers in differend kinds of sql tables.

there's base type customer in entityframework database, column called type.

depending on customer.type user should able enter different types of information.

so customer.type store customer1, customer2 , on... depending on type, information stored in database table.

customer base information (name, postal address) belongs customers table, whereas if customer of type customer1, wpf ui should display additional usercontrol exposes controls fill in information table customer1.

is there clean way in wpf mvvm this?

yes, can data templates, explain or read similar approach @ wpf datatemplate binding depending on type of property

you can implement different viewmodels , views each type, i.e customer1viewmodel - customer1view, customer2viewmodel - customer2view ...

then, based on type, create appropriate viewmodel type.

in ui want enter data add data templates:

<usercontrol>     <usercontrol.resources>           <datatemplate datatype="{x:type viewmodels:customer1viewmodel}">                     <views:customer1view/>                 </datatemplate>             <datatemplate datatype="{x:type viewmodels:customer2viewmodel}">                     <views:customer2view/>                 </datatemplate>      </usercontrol.resources>     <grid>         <!--main content-->         <contentcontrol content="{binding customerviewmodel}"/>     </grid>  </usercontrol> 

so, if instance in binded property customerviewmodel customer1viewmodel, displayed customer1view user control.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -