wpf controls - WPF "partial forms" -
i'm making application db migrations. made multithreaded framework wpf gui. put someting in namespace/folder:
class : migrator { public override run(){ //i need string valueofmycustomfieldonform = xyz.text; //example int count = 500; for(int = 0; < 500; i++){ //do here onprogresschanged(...); //call event, gui updated } oncompleted(...); //migration completed } }
then using reflection put classes in namespace onto dropdown list. when choose 1 in list , click start, thread code in run method started.
db host: textbox db username: textbox db password: textbox -- migrator custom field 1: textbox migrator custom field 2: textbox ... -- list migrated items - irrelevant
there few commong field on gui (like database host, username etc...). of migrators need custom fields on gui (for example 3 textbox fields). best way in wpf? need part of gui dynamic.
there's lot of seemingly-irrelevant information in question, - think - mechanisms creating metadata-driven uis in wpf. here's way approach problem:
suppose want build property-sheet-like ui: grid displays row each property, prompt , input control of kind. this, you're going need collection of objects, each item in collection including properties describe property , value. simple design class exposes prompt
property , value
property , implements change notification.
once have created , populated collection, can implement itemscontrol
displays in grid:
<itemscontrol itemssource="{binding properties}" grid.issharedsizescope="true"> <itemscontrol.itemtemplate> <datatemplate datatype="propertyviewmodel"> <grid> <grid.columndefinitions> <columndefinition sharedsizegroup="prompt"/> <columndefinition sharedsizegroup="value"/> </grid.columndefinition> <grid.rowdefinitions> <rowdefinition/> </grid.rowdefinitions> </grid> <label content="{binding prompt}"/> <textbox grid.column="1" text="{binding value, mode=twoway}"/> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol>
this pretty simple - complicated thing using grid.issharedsizescope
of grids control creates use same column widths. use listview
instead of itemscontrol
, though using listview
introduces bunch of issues surrounding focus , selection may not want deal with.
note because of magic wpf template matching, conceivably implement value
property object
, , create different templates handle different possible types of value
property - real property sheet does. this, you'd create template each type, e.g.:
<datatemplate datatype="{x:type system:string}"> <textbox text="{binding value, mode=twoway}"/> </datatemplate> <datatemplate datatype="{x:type system:datetime}"> <datepicker value="{binding value, mode=twoway}"/> </datatemplate>
etc. you'd change template propertyviewmodel
instead of showing value
in textbox
, uses contentpresenter
, e.g.:
<contentpresenter grid.column="1" content="{binding}"/>
Comments
Post a Comment