How to render controls defined in Json structure using MvvmCross? -
i have situation view definition(i.e. content gets displayed on layout file) defined in json structure. need able define json structure along bindings , code should able dynamically create controls based on json structure , fill out layout.
i able accomplish same using code below.
protected override void oncreate(bundle bundle) { base.oncreate(bundle); firstviewmodel firstviewmodel = new firstviewmodel() { id = 1001, firstname = "amit", middlename = string.empty, lastname = "taparia", race = "asian", isusnational = false }; this.viewmodel = firstviewmodel imvxviewmodel; var bindings = this.createinlinebindingtarget<firstviewmodel>(); this.root = new rootelement("main view", null, null). { new section("personal information") { new stringelement("employee#","enter employee#").bind(bindings,vm => vm.id) new entryelement("firstname","enter first name").bind(bindings,vm=>vm.firstname), new entryelement("middlename","enter middle name").bind(bindings, vm=> vm.middlename), new entryelement("lastname","enter last name","amit",null).bind(bindings, vm => vm.lastname), new entryelement("race","enter race").bind(bindings,vm => vm.race), new booleanelement("us national",true,).bind(bindings, vm => vm.isusnational). }, }; }
but need able same using structure defined in json file. know can using mvvmcross, dont know how this.
i came across these 3 sample solutions a) customermanagement b) customermanager.autoview here see have basecustomereditview.cs there json structure defined, code commented out. c) dialogexamples
couple of questions
1) whats difference between using autoview , mvxdialog? 1 , same thing?
2) there potential limitations using control structure defined in json file. see 1 problem related alignment. wont have control on alignment of controls defined in json file.
3) how achieve rendering/binding using structure defined in json file?
looking forward responses.
dialog provides "a foundation create dialog boxes , show table-based information without having write dozens of delegates , controllers user interface" (from https://github.com/migueldeicaza/monotouch.dialog)
the idea of autoviews provide layer of auto-generated uis built largely on top of dialog, prototyping possibly families of apps - see should wait autoview? , http://slodge.blogspot.co.uk/2012/10/cross-platform-views-for-mvvmcross-ideas.html
the current state of autoviews there initial implementation available on android , ios, , there small sample shows use of implementation at: https://github.com/slodge/mvvmcross-tutorials/tree/master/autoviewexamples
the main focus of demo uses auto
objects describe ui in viewmodel - e.g.:
private keyeddescription getdialogautoview() { var auto = new rootauto(caption: "some dialog info") { new sectionauto(header: "strings") { new entryauto(caption: "name", bindingexpression: () => name), new entryauto(caption: "password", bindingexpression: () => password) { password = true }, }, new sectionauto(header: "booleans") { new booleanauto(caption: "is available", bindingexpression: () => isavailable), new checkboxauto(caption: "is active", bindingexpression: () => isactive), }, new sectionauto(header: "datetimes") { new dateauto(caption: "date of birth", bindingexpression: () => dateofbirth), new timeauto(caption: "when", bindingexpression: () => preferredcontacttime), }, new sectionauto(header: "debug info") { new stringauto(caption: "name", bindingexpression: () => name), new stringauto(caption: "password", bindingexpression: () => password), new stringauto(caption: "is available", bindingexpression: () => isavailable), new stringauto(caption: "is active", bindingexpression: () => isactive), new stringauto(caption: "date of birth", bindingexpression: () => dateofbirth), new stringauto(caption: "when", bindingexpression: () => preferredcontacttime), }, }; return auto.toelementdescription(); }
instead of these auto
objects, json format description available, there's not documentation on today. example files exist in https://github.com/slodge/mvvmcross-tutorials/blob/master/sample%20-%20customermanagement/customermanagement%20-%20autoviews - example https://github.com/slodge/mvvmcross-tutorials/blob/master/sample%20-%20customermanagement/customermanagement%20-%20autoviews/customermanagement.droid/assets/defaultviews/newcustomerviewmodel/dialog.json
these json files reflection-based - built around names , properties of dialog classes.
for specific case, think i'd recommend don't use autoviews json format.
it sounds have more specific requirement - want viewmodels download models web , viewmodels construct uis these descriptions.
because of recommend start describing own business models in c# pocos - these can serialised on network connection (e.g. using json.net) , viewmodels , views can work out how display them.
as know is possible have method binding in mvvmcross using fluent api?, can bind ui dictionary or other 'dynamic' viewmodel structure if want - suspect useful when displaying , binding dynamic form data.
it may can use either auto
or json parts of autoviews part of last display step - don't think network transfer should done in terms of dialog elements - stick business domain objects there.
Comments
Post a Comment