c# - how to use panorama item selectionchanged -


i attempting detect current panorama item user on , toggle application bar icon button isenabled property accordingly. have not had luck on how implement feature this, or detect current panorama item. specifically, use selecteditem property , detect name of panorama items instead of selectedindex property because panorama items may change order. there way this? far have following:

mainpage.xaml

<controls:panorama selectionchanged="panoramaitemselectionchanged">                       <!--panorama item one-->             <controls:panoramaitem header="statuses" >                 ...             </controls:panoramaitem>              <!--panorama item two-->             <controls:panoramaitem header="mentions" >                 ...             </controls:panoramaitem>              <!--panorama item three-->             <controls:panoramaitem header="messages" >                 ...             </controls:panoramaitem>              <!--panorama item four-->             <controls:panoramaitem header="favorites" >                 ...             </controls:panoramaitem>          </controls:panorama>  

mainpage.xaml.cs

private void panoramaitemselectionchanged(object sender, selectionchangedeventargs e)     {         string currentpanoramaitem = e.addeditems[0] string;          switch (currentpanoramaitem)         {             case "statuses":                 //show application bar button?                 break;             case "mentions":                 //show application bar button?                 break;             case "messages":                 ((applicationbariconbutton)applicationbar.buttons[0]).isenabled = true;                 break;             case "favorites":                 //show application bar button?                 break;             default:                 return;         }                 } 

my selectionchanged implementation not work reason. ideas (with example please)?

testing using header name bad idea, since code break if rename panorama item headers, or localize them.

you work out selected index, break if re-ordered items:

        panoramaitem selecteditem = (panoramaitem)e.addeditems[0];         int selectedindex = mainpanorama.items.indexof(selecteditem); 

the robust way set tag on panorama items , test that:

xaml:

   <phone:panorama x:name="mypanorama" selectionchanged="panorama_selectionchanged_1">          <phone:panoramaitem header="the places" tag="places">         </phone:panoramaitem>          <phone:panoramaitem header="the routes" tag="routes">         </phone:panoramaitem>     </phone:panorama> 

code behind:

    private void panorama_selectionchanged_1(object sender, selectionchangedeventargs e)     {         if (e.addeditems.count < 1) return;         if (!(e.addeditems[0] panoramaitem)) return;          panoramaitem selecteditem = (panoramaitem)e.addeditems[0];          string strtag = (string)selecteditem.tag;         if (strtag.equals("places"))             // places stuff         else if (strtag.equals("routes"))             // routes stuff       } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -