wpf - How to update the UI using bindings -
wpf - How to update the UI using bindings -
i have datagrid , 2 listboxes in window. using entity framework connect sql server. depending on selections create in listboxes parameters passed stored procedure , info datagrid retrieved. able implement functionality without using mvvm. know ways implement using mvvm. please help me out. in advance.
first of all, mvvm separating concerns of code appropriate area. example, talking database via ef should done in model1. viewmodel responsible holding data, , shaping or massaging create more suitable display (i.e. transforming enums colors2, etc).
to implement functionality in mvvm way, need utilize binding, , bind viewmodel view:
<mycontrol> <layoutroot> <listbox itemssource={binding myitems} selecteditem={binding myselection} /> </layoutroot> </mycontrol>
in code behind view:
public class mycontrol { public mycontrol() { this.datacontext = new myviewmodel(); } }
and viewmodel this:
public class myviewmodel : inotifypropertychanged { public observablecollection<mydataobject> myitems { { homecoming _myitems; } set { _myitems = value; onpropertychanged("myitems"); } } public mydataobject myselection { get; set; } public void dosomethingwithdatabase() { model.dosomething(myselection); } }
this simple illustration illustrate required if things mvvm way (and i've deliberately missed out bunch of stuff). proper illustration , document essential bits need know take @ to the lowest degree chapter in book, i'll refer msdn article farther reading: implementing model-view-viewmodel pattern.
1 , model may stepping stone if implement soa, model might phone call service talks database. 2 can done converters in view, may not possible or practical in converter.
wpf entity-framework stored-procedures mvvm datagrid
Comments
Post a Comment