c# - How to set the longitude and latitude from ViewModel in bing maps in windows phone 7 -


i want give longitude , latitude viewmodel.

now using like:-

 private void button1_click(object sender, routedeventargs e)     {         pushpin p = new pushpin();         p.background = new solidcolorbrush(colors.yellow);         p.foreground = new solidcolorbrush(colors.black);         p.location = new geocoordinate(double.parse(longitude.text), double.parse(latitude.text));//longitude , latitude         p.content = "i'm here";//to show place located         map1.children.add(p);         map1.setview(new geocoordinate(double.parse(longitude.text), double.parse(latitude.text), 200), 9);     } 

my xaml is:-

  <grid x:name="mappageuicontainer" grid.row="1" margin="2,0,2,0">         <my:map copyrightvisibility="collapsed" logovisibility="collapsed" credentialsprovider=""  mode="aerialwithlabels" height="543" horizontalalignment="left" name="map1" verticalalignment="top" width="480" margin="2,100,0,0"  />         <border borderbrush="silver" borderthickness="1" height="100" horizontalalignment="left" margin="0,0,0,0" name="border1" verticalalignment="top" width="476" background="#ffa3a371">             <textblock text="map example" horizontalalignment="center" fontsize="32" fontweight="bold" verticalalignment="center" />         </border>         <textbox height="72" horizontalalignment="left" margin="6,627,0,0" name="longitude" text="" verticalalignment="top" width="200" />         <textbox height="72" horizontalalignment="left" margin="260,627,0,0" name="latitude" text="" verticalalignment="top" width="200" />         <button content="set" horizontalalignment="left" margin="190,690,0,0" name="button1" verticalalignment="top" click="button1_click" />     </grid> 

here want give pushpin, longitude, latitude view model. please let me know how achieve this?

thanks in advance..

i have try this..

public class mappageviewmodel : reactiveobject {      public static string _longitude;     public string longitude     {         { return _longitude; }         set { this.raiseandsetifchanged(x => x.longitude, value); }     }      public static string _latitude;     public string latitude     {         { return _latitude; }         set { this.raiseandsetifchanged(x => x.latitude, value); }     }      public reactiveasynccommand setbutton { get; set; }      public mappageviewmodel()     {         setbutton = new reactiveasynccommand();         setbutton.subscribe(x => {              pushpin p = new pushpin();             p.background = new solidcolorbrush(colors.yellow);             p.foreground = new solidcolorbrush(colors.black);             p.location = new geocoordinate(double.parse(longitude), double.parse(latitude));             p.content = "i'm here";//to show place located             //map1.children.add(p);             //map1.setview(new geocoordinate(double.parse(longitude), double.parse(latitude), 200), 9);         });     }   } 

but don't know how set map1.children.add() , map1.setview , how bind these values in map?

hi clemens. have tried instruction. showing error.

screen shot of error message

and have try this:-

public mappageviewmodel()     {         pushpinitems = new observablecollection<pushpinitem>();         pushpinitem pp = new pushpinitem();         setbutton = new reactiveasynccommand();         setbutton.subscribe(x => {             pp.location = new geocoordinate(double.parse(longitude), double.parse(latitude));             pp.text = "i'm here";             pushpinitems.add(pp);         });     } 

but here run time error happening. please let me know did mistake.

in proper mvvm approach have mapitemscontrol itemtemplate pushpin, , bind observablecollection of pushpin data items in view model:

public class pushpinitem {     public geocoordinate location { get; set; }     public string text { get; set; } }  public class mappageviewmodel : reactiveobject {     public observablecollection<pushpinitem> pushpinitems { get; set; }     ...      public mappageviewmodel()     {         pushpinitems = new observablecollection<pushpinitem>();         setbutton = new reactiveasynccommand();          setbutton.subscribe(x =>         {             pushpinitems.add(new pushpinitem             {                 location = new geocoordinate(...),                 text = ...             });         });     } } 

xaml:

<map:map ...>     <map:mapitemscontrol itemssource="{binding pushpinitems}">         <map:mapitemscontrol.itemtemplate>             <datatemplate>                 <map:pushpin location="{binding location}" content="{binding text}"                              background="yellow" foreground="black"/>             </datatemplate>         </map:mapitemscontrol.itemtemplate>     </map:mapitemscontrol> </map:map> 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -