Saturday, 15 August 2015

c# - Mass Explicit Binding Update in WPF -



c# - Mass Explicit Binding Update in WPF -

i writing wpf application , in few models. each model has editor command can view & edit objects of model.

for example:

<label content="{binding id}" /> <textbox text="{binding firstname}" /> <textbox text="{binding lastname}" /> <textbox text="{binding department}" /> <textbox text="{binding telephonenumber}" /> <xceed:byteupdown value="{binding accesslevel1}" maximum="64" /> <xceed:byteupdown value="{binding accesslevel2}" maximum="64"/> <xceed:integerupdown value="{binding pin}" /> <xceed:integerupdown value="{binding keycode}" /> <xceed:integerupdown value="{binding userlimit}" />

whenever alter value updated in model, great; want add together save/cancel behaviour:

on "save", , then, info copied model, , on "cancel", info reloaded model.

i not sure how accomplish it.

one way thought of marking bindings w/ updatesourcetrigger=explicit, requires big amount of boilerplate code update source , can bit cumbersome, since models have more 20 editable properties.

is there improve way of doing so?

edit: thought maybe reading in future have solution used.

given class key:

class key { private keyviewmodel viewmodel; public keyviewmodel viewmodel { { if (viewmodel == null) viewmodel = new keyviewmodel(this); homecoming viewmodel; } } // -=-=- lots & lots of properties -=-=- // } public class keyviewmodel : key { public key parent { get; set; } public keyviewmodel(key parent) { parent = parent; copyfrommodel(); } public void copytomodel() { type t = typeof(key); var props = t.getproperties(); foreach (var p in props) { if (p.canwrite) p.setvalue(parent, p.getvalue(this)); } } public void copyfrommodel() { type t = typeof(key); var props = t.getproperties(); foreach (var p in props) { if (p.canwrite) p.setvalue(this, p.getvalue(parent)); } } }

what not updating model (keep values @ viewmodel level) until 'saved', , reloading values model viewmodel when 'canceled' ?

c# wpf data-binding

No comments:

Post a Comment