Sunday 15 May 2011

monotouch - How to get MvvmCross MKAnnotation real time update binding -



monotouch - How to get MvvmCross MKAnnotation real time update binding -

i'm attempting mkmapkit annotations updating in real time in xamarin ios project.

i'm using mvvmcross , have based implementation on @slodge code , it's working great.

https://gist.github.com/slodge/6070386

what i'd able stuart alludes in 1 of comments.

public class houseannotation : mkannotation { public houseannotation(house house) { // utilize house here... // in theory data-bind house (e.g. if it's location move...) } public override cllocationcoordinate2d coordinate { get; set; } }

how go binding house coordinates houseannotation.coordinate?

so far have been doing bindings like:

var bindingset = this.createbindingset<view, viewmodel>();

which works straight forwards in viewdidload , have access need.

i sense i'd naturally want do

var bindingset = myview.createbindingset<houseannotation, house>();

but means passing reference myview downwards houseannotation can used phone call createbindingset on , uncertainty work because house , houseannotation aren't subclasses of mvx base of operations class.

i sense i'm missing bit of puzzle here. able help me out here?

i understand houses unlikely move i'm preparing eventualities!

you can subscribe changes on house.location property using weaksubscribe

the reply in n+38 @ around 24mins.

https://www.youtube.com/watch?v=jtxxms3ohhy

public class houseannotation : mkannotation { private house _house; public houseannotation(house house) { // create local reference _house = house; // update annotation coordinate set first time round updatelocation() // subscribe notified of changes location property trigger updatelocation method _house.weaksubscribe<house>("location", (s, e) => updatelocation()); } private void updatelocation() { // convert our house.location cllocationcoordinate2d , set on mkannotation.coordinate property coordinate = new cllocationcoordinate2d(_house.location.lat, _house.location.lng); } public override cllocationcoordinate2d coordinate { { homecoming coord; } set { // phone call willchangevalue , didchangevalue utilize kvo // mkannotation setting coordinate on // annotation instance causes associated annotation // view move new location. // animate smooth transition uiview.animate(0.25, () => { willchangevalue ("coordinate"); coord = value; didchangevalue ("coordinate"); }); } } }

monotouch xamarin mapkit mvvmcross mvxbind

No comments:

Post a Comment