wpf - MVVM pattern - executing view operations -


i'm using mvvm pattern (with mvvm light) build xaml app (win8). have listview, bound property of viewmodel. have button triggers operation on viewmodel, updates property (which results in updating listview). button uses commanding execute operation on viewmodel. far good.

the problem after list refreshed need perform operation strictly belongs view, not viewmodel. should scroll list specific item. how trigger operation? should use specific listview event?

using eventhandler , scrollintoview(object) method can achieve want without using references of view inside viewmovel , respecting mvvm pattern.

create event in viewmodel this:

public event eventhandler scrolllistview; 

in view add callback scroll listview when property updated:

viewmodel vm; vm.scrolllistview += (sender, e) => {      var specificitem = **some item**;      mylistview.selecteditem = specificitem;       mylistview.updatelayout();      mylistview.scrollintoview(mylistview.selecteditem); }; 

then in viewmodel when update property , want scroll listview:

if (this.scrolllistview != null) {     this.scrolllistview(this, eventargs.empty); } 

this how tweaks each case of course.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -