c# - Back Button on first page when NavigationPage used -


i have custom listview on xamarin.forms apps has switch control multi selection. have issue in backbutton on first page of app. button on first page not required redirects black page. know has navigation.pushasync. not figure out change required. if can direct me in correct way wil helpful.

here selectmultiplebasepage.cs page:

using system; using system.collections.generic; using system.componentmodel; using system.linq; //using system.reflection.emit; using system.text; using xamarin.forms;  namespace _____ {     public class selectmultiplebasepage<t> : contentpage     {         public class wrappedselection<t> : inotifypropertychanged         {             public t item { get; set; }             bool isselected = false;             public bool isselected             {                                 {                     return isselected;                 }                 set                 {                     if (isselected != value)                     {                         isselected = value;                         propertychanged(this, new propertychangedeventargs("isselected"));                         //                      propertychanged (this, new propertychangedeventargs (nameof (isselected))); // c# 6                     }                 }             }             public event propertychangedeventhandler propertychanged = delegate { };         }         public class wrappeditemselectiontemplate : viewcell         {             public wrappeditemselectiontemplate()                 : base()             {                  grid objgrid = new grid();                 objgrid.backgroundcolor = color.gray;                 objgrid.rowdefinitions.add(new rowdefinition                 {                     height = new gridlength(1, gridunittype.star)                 });                  objgrid.columndefinitions.add(new columndefinition                 {                     width = new gridlength(75, gridunittype.absolute)                 });                 objgrid.columndefinitions.add(new columndefinition                 {                     width = new gridlength(1, gridunittype.star)                 });                 objgrid.columndefinitions.add(new columndefinition                 {                     width = gridlength.auto                 });                  //                 // column 1:-                 image objimage = new image();                 objimage.backgroundcolor = color.green;                 objimage.setbinding(image.sourceproperty, new binding("item.image"));                 objgrid.children.add(objimage, 0, 0);                  //                 // column 2:-                 stacklayout objstacklayoutcol2 = new stacklayout();                 objgrid.children.add(objstacklayoutcol2, 1, 0);                  label name = new label()                 {                     text = "name"                 };                 label date = new label()                 {                     text = "date"                 };                 name.setbinding(label.textproperty, new binding("item.name"));                 date.setbinding(label.textproperty, new binding("item.date"));                 objstacklayoutcol2.children.add(name);                 objstacklayoutcol2.children.add(date);                  //                 // column 3:-                 switch mainswitch = new switch();                 mainswitch.setbinding(switch.istoggledproperty, new binding("isselected"));                 objgrid.children.add(mainswitch, 2, 0);                  view = objgrid;               }         }         public list<wrappedselection<t>> wrappeditems = new list<wrappedselection<t>>();         public selectmultiplebasepage(list<t> items)         {             wrappeditems = items.select(item => new wrappedselection<t>() { item = item, isselected = false }).tolist();             listview mainlist = new listview()             {                 itemssource = wrappeditems,                 itemtemplate = new datatemplate(typeof(wrappeditemselectiontemplate)),             };              mainlist.itemselected += (sender, e) =>             {                 if (e.selecteditem == null) return;                 var o = (wrappedselection<t>)e.selecteditem;                 o.isselected = !o.isselected;                 ((listview)sender).selecteditem = null; //de-select             };             content = mainlist;              if (device.os == targetplatform.winphone)             {   // fix issue rows badly sized (as tall screen) on winphone8.1                 mainlist.rowheight = 40;                 // need icons windows app bar (other platforms can use text)                 toolbaritems.add(new toolbaritem("all", "check.png", selectall, toolbaritemorder.primary));                 toolbaritems.add(new toolbaritem("none", "cancel.png", selectnone, toolbaritemorder.primary));             }             else             {                 toolbaritems.add(new toolbaritem("all", null, selectall, toolbaritemorder.primary));                 toolbaritems.add(new toolbaritem("none", null, selectnone, toolbaritemorder.primary));             }         }         void selectall()         {             foreach (var wi in wrappeditems)             {                 wi.isselected = true;             }         }         void selectnone()         {             foreach (var wi in wrappeditems)             {                 wi.isselected = false;             }         }         public list<t> getselection()         {             return wrappeditems.where(item => item.isselected).select(wrappeditem => wrappeditem.item).tolist();         }     } } 

listpage.cs:

using system; using system.collections.generic; using system.io; using system.linq; //using system.reflection.emit; using system.text; using system.xml.serialization; using xamarin.forms;  namespace ______ {     public class listpage : contentpage     {          selectmultiplebasepage<checkitem> multipage= null;         public listpage ()         {             loadlist();         }          async void loadlist()         {             var items = new list<checkitem>();             items.add(new checkitem { name = "xamarin.com", date = "01/01/2015", image = "img.png" });             items.add(new checkitem { name = "twitter", date = "01/01/2015", image = "img.png" });             items.add(new checkitem { name = "facebook", date = "01/01/2015", image = "img.png" });              if (multipage == null)                 multipage = new selectmultiplebasepage<checkitem>(items) { title = "check apply" };              await navigation.pushasync(multipage);         }     } } 

app.cs:

using system; using system.collections.generic; using system.linq; using system.text;  using xamarin.forms;  namespace ____ {     public class app : application     {         public app ()         {             mainpage = new navigationpage(new listpage());         }          protected override void onstart ()         {             // handle when app starts         }          protected override void onsleep ()         {             // handle when app sleeps         }          protected override void onresume ()         {             // handle when app resumes         }     } } 

instead of doing await navigation.pushasync(multipage); change to:

content = multipage; 

this should set page content listpage have passed navigationpage selectmultiplebasepage<t> setup in code. , should first page in navigation , there shouldn't button present.

edit: sorry try changing to: content = multipage.content;


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -