silverlight - Binding WP7 Maps control to ViewModel, Problem with MapMode -


i trying reproduce bingmaps sample of windows phone 7 trainingkit: http://msdn.microsoft.com/en-us/wp7trainingcourse_usingbingmapslab_topic2.aspx#_toc271039352

but instead of wiring in codebehind i'd use viewmodel.

everything works fine except binding mode property (aerial or road) causes xamlparseexception. there problem because isn't simple property?

this original xaml:

            <my:map name="map"                     credentialsprovider="{binding credentialsprovider}">                  <my:map.mode>                     <my:aerialmode shoulddisplaylabels="true" />                 </my:map.mode>             </my:map> 

the map.mode can changed codebehind.

instead trying following:

        <my:map x:name="map"                 credentialsprovider="{binding credentialsprovider}"                 zoomlevel="{binding zoom, mode=twoway}"                 center="{binding center, mode=twoway}"                 mode="{binding mapmode}" /> 

and important part of viewmodel:

    private mapmode _mapmode = new aerialmode(true);     public mapmode mapmode     {         { return _mapmode; }         set         {             _mapmode = value;             raisepropertychanged("mapmode");         }     }      private void changemapmode()     {         if (mapmode aerialmode)         {             mapmode = new roadmode();         }         else         {             mapmode = new aerialmode(true);         }     } 

thanks help!

solved.

"mode" isn't dependency property. cannot bound.

my workaround:

  • added dependency property view (=page)
  • bound dependency property property in viewmodel (via code in constructor)
  • set mode of map control in propertychanged callback handler

    //constructor public mainpage() {     initializecomponent();     datacontext = new mainviewmodel();     binding b = new binding("mapmode");     this.setbinding(mapmodeproperty, b); }   //dependencyproperty. no need corresponding clr-property. public static readonly dependencyproperty mapmodeproperty =     dependencyproperty.register("mapmode", typeof(mapmode), typeof(mainpage),      new propertymetadata(onmapmodechanged));   //callback private static void onmapmodechanged(dependencyobject element,        dependencypropertychangedeventargs e) {     ((mainpage)element).map.mode = e.newvalue mapmode; } 

hope 1 others!


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -