c# - pivot application windows phone 8.1 navigation -


i developing windows phone application firm.

i've manually created pivot items in basic page. application working fine except button navigation. when click on button inside pivot item navigating desired page when click button navigating pivot item 1 instead of 1 click event originated.

my xaml looks this

<grid x:name="contentroot"><pivot x:name="test" title="test book" fontsize="{themeresource textstyleextralargefontsize}">         <!--pivot item one-->         <pivotitem x:name="pitem1" header="item1">      <grid>                 <grid.rowdefinitions>                         <rowdefinition height="auto" />                         <rowdefinition height="5*" />                         <rowdefinition height="5*" />                         <rowdefinition height="5*" />                     </grid.rowdefinitions>                 <grid.columndefinitions>                                           <columndefinition width="10*" />                     <columndefinition width="*" />                     <columndefinition width="10*"/>                     <columndefinition width="*" />                     <columndefinition width="10*" />                 </grid.columndefinitions>                 <button x:name="bt1" grid.row="1" grid.rowspan="2" grid.column="0" grid.columnspan="1" content="" horizontalalignment="stretch" verticalalignment="stretch" borderthickness="0" click="bt1_click"/>                                <button x:name="bt2" grid.row="2" grid.rowspan="2" grid.column="2" grid.columnspan="1" content="" horizontalalignment="stretch" verticalalignment="stretch" click="bt2_click"/>                              <button x:name="bt3" grid.row="3" grid.rowspan="2" grid.column="4" grid.columnspan="1" content="" horizontalalignment="stretch" verticalalignment="stretch" click="bt3_click"/>                           <rectangle strokethickness="0" grid.row="1" grid.rowspan="3" grid.column="0" grid.columnspan="11" stroke="#ff015c1f">                             </rectangle>             </grid>         </pivotitem>         <!--pivot item one-->         <pivotitem x:name="pitem2" header="item2" >                              <grid>                     <grid.rowdefinitions>                         <rowdefinition height="auto" />                         <rowdefinition height="5*" />                         <rowdefinition height="5*" />                         <rowdefinition height="5*" />                         <rowdefinition height="5*" />                     </grid.rowdefinitions>                     <grid.columndefinitions>                         <columndefinition width="10*" />                         <columndefinition width="*" />                         <columndefinition width="10*" />                     </grid.columndefinitions>                     <button x:name="bt4" grid.row="1" content="" horizontalalignment="stretch" verticalalignment="stretch" click="bt4_click"/ >                 <button x:name="bt5" grid.row="1" grid.column="2" content="" horizontalalignment="stretch" verticalalignment="stretch" click="bt5_click" />                 </grid>                     </pivotitem>         <!--pivot item two-->         <pivotitem x:name="pitem3" header="item3">                          <grid >                 <grid.rowdefinitions>                     <rowdefinition height="auto" />                     <rowdefinition height="10*" />                     <rowdefinition height="10*" />                     <rowdefinition height="10*" />                 </grid.rowdefinitions>                 <grid.columndefinitions>                     <columndefinition width="10*" />                     <columndefinition width="*" />                     <columndefinition width="10*" />                 </grid.columndefinitions>                 <button x:name="bt6" grid.row="1"  content="" horizontalalignment="stretch" verticalalignment="stretch" click="bt6_click"/>                             <button x:name="bt7" grid.row="1" grid.column="2" content="" horizontalalignment="stretch" verticalalignment="stretch" click="bt7_click"/>                               <button x:name="bt8" grid.row="2"  content="" horizontalalignment="stretch" verticalalignment="stretch" click="bt8_click" />               </grid>         </pivotitem>  

for example : if click "bt7" present inside pivot item 3, navigates page , when click button navigating pivot item 1 instead of item 3.

am missing or problem have created pivot item manually?

i'm new c# , xaml. highly appreciated.

update :

    public home()     {         this.initializecomponent();                 this.navigationcachemode = navigationcachemode.required;         this.navigationhelper = new navigationhelper(this);         this.navigationhelper.loadstate += this.navigationhelper_loadstate;         this.navigationhelper.savestate += this.navigationhelper_savestate;     }     public navigationhelper navigationhelper     {         { return this.navigationhelper; }     }     public observabledictionary defaultviewmodel     {         { return this.defaultviewmodel; }     }     private void navigationhelper_loadstate(object sender, loadstateeventargs e)     {     }    private void navigationhelper_savestate(object sender, savestateeventargs e)     {     }     #region navigationhelper registration     protected override void onnavigatedto(navigationeventargs e)     {            this.navigationhelper.onnavigatedto(e);     }     protected override void onnavigatedfrom(navigationeventargs e)     {         this.navigationhelper.onnavigatedfrom(e);              }     #endregion            private async void bt1_click(object sender, routedeventargs e)     {             home obj = new home();             var result = await obj.gettoken4(sid);            if (result.substring(0, 2) == "no")             {                                     messagedialog msgbox = new messagedialog("no records found", "e-book!");                 await msgbox.showasync();                              }             else             {                                   this.frame.navigate(typeof(firstpage), result);             }         }          }     private async task<string> gettoken4(string sid)     {         string postdata = "id=" + sid;         var res = await post4("parameter", postdata);         return res;     }     private async task<string> post4(string url, string postdata)     {         var request = webrequest.create(new uri("myurl")) httpwebrequest;         request.method = "post";         request.contenttype = "application/json";         byte[] data = encoding.utf8.getbytes(postdata);         //request.contentlength = data.length;         using (var requeststream = await task<stream>.factory.fromasync(request.begingetrequeststream, request.endgetrequeststream, request))         {             await requeststream.writeasync(data, 0, data.length);         }         webresponse responseobject = await task<webresponse>.factory.fromasync(request.begingetresponse, request.endgetresponse, request);         var responsestream = responseobject.getresponsestream();         var sr = new streamreader(responsestream);         string received = await sr.readtoendasync();         return received;     }     private async void bt2_click(object sender, routedeventargs e)     {        home obj = new home();             var result = await obj.gettoken4(sid);            if (result.substring(0, 2) == "no")             {                                     messagedialog msgbox = new messagedialog("no records found", "e-book!");                 await msgbox.showasync();                              }             else             {                                   this.frame.navigate(typeof(secondpage), result);             }         }               }     private async task<string> gettoken5(string sid)     {         string postdata = "dep=" + sid;         var res = await post5("parameter1", postdata);         return res;     }     private async task<string> post5(string url, string postdata)     {         var request = webrequest.create(new uri("myurl")) httpwebrequest;         request.method = "post";         request.contenttype = "application/json";         byte[] data = encoding.utf8.getbytes(postdata);         //request.contentlength = data.length;         using (var requeststream = await task<stream>.factory.fromasync(request.begingetrequeststream, request.endgetrequeststream, request))         {             await requeststream.writeasync(data, 0, data.length);         }         webresponse responseobject = await task<webresponse>.factory.fromasync(request.begingetresponse, request.endgetresponse, request);         var responsestream = responseobject.getresponsestream();         var sr = new streamreader(responsestream);         string received = await sr.readtoendasync();         return received;     }  } } 

your page reloaded when navigating , therefor controls in default state (e.g. pivot on first item).

you can either save/restore state in onnavigatedto , onnavigatedfrom methods, or activate page caching setting page's navigationcachemode enabled or required in constructor.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -