c# - What happens internally when you bind to ItemSource? -
i'm curious how works, because have mainviewmodel
, has property called subviewmodel
has property of observablecollection (we'll call property1
.)
i've implemented inotifychangedproperty on everything.
my main window
<window .. datacontext="{binding mainviewmodel}" /> ... <stackpanel datacontext="{binding subviewmodel}"> <local:somecontrol datacontext="{binding}" /> </stackpanel> </window>
and usercontrol
<usercontrol name="somecontrol"> <datagrid name="mydatagrid" itemsource="{binding property1, mode=twoway}" currentcellchanged="testmethod" /> ... </usercontrol>
in test method, test figure out why changes not propegating main view model this
private void testmethod() { var vm = this.datacontext subviewmodel; var itemsourceobservablecollection = mydatagrid.itemssource observablecollection<mytype>; //i thought vm.property1 equal itemsourceobservablecollection //but not, itemsourceobservablecollection shows changes i've made //vm.property1 has not reflected changes made, though though same item }
so figured out itemsource must create copy of item bind to? i'm stuck here, how manually notify viewmodel property has changed , needs update? thought inotifypropertychanged's job?
i think part of problem lack understanding of how kinda works internally. if can point blog post, or documentation me understand why code isn't working way expected, great.
1) no copy made.
2) observablecollection
propogate changes made collection, not items within collection. you'll see additions, deletions etc. not property changes items within collection.
3) if want see changes made individual items in observablecollection, need implement inotifypropertychanged
on items.
Comments
Post a Comment