c# - Make a large model observable -


i'm on second wpf project , ran uncomfortable situation. model:

public class layout {     public string name { get; set; }     public motor motor { get; set; } }  public class motor {     public string property1 { get; set; }     ...     public string property150 { get; set; } } 

this mainviewmodel:

public class mainviewmodel : viewmodelbase {     public motor motor {get; set;}     ... } 

ok, have bound 150 properties of motor class textboxes:

<textbox text="{binding layout.motor.property1}"/> 

problem 1) if want trigger action whenever user changes 1 of these, have implement 150 times??

    private string property1 { get; set; }     public string property1     {         { return property1; }         set         {             property1 = value;             raisepropertychanged(() => property1);         }     } 

problem 2) have implement in mainviewmodel, in model "motor" or need "motorviewmodel"? of these mean lot of copy&paste , totally useless coding..

thank , feedback!

first off, raisepropertychanged ui, notify when code changes item. of course, can manually listen well, don't.

you don't use auto-property backing field, may due propertychanged implementation.

now that's out of way:

yes, need implement that, or similar allowed propertychanged raised 150 times. now, 1 wonders why on earth have 150 properties on object, may want reconsider design first. if need them, yes, copy-paste in future. consider writing code snippet make go faster.

to answer other question, put in "model" object long object can serve dto. in other words, isn't tied model in way (say, model functionality) can float between layers. can put inpc on data contracts, doesn't hurt anything.

one other thing consider, if want notify ui when motor changes opposed individual properties, can notify on motor property , bindings update.


Popular posts from this blog