c# - Xamarin.Forms Caousel Page Indicator -
i have xamarin.forms (1.4.2.6359) project using visual studio 2013 , have created carousel page below. want add page indicators, i.e. dots on top of carousel page. able done xamarin forms carouselpage?
public class splashpage : carouselpage { public splashpage () { this.children.add(new carouselchild("logo.png", "welcome")); this.children.add(new carouselchild("settings.png", "settings")); } } class carouselchild : contentpage { public carouselchild(string image, string text) { stacklayout layout = new stacklayout { horizontaloptions = layoutoptions.centerandexpand, verticaloptions = layoutoptions.centerandexpand, }; layout.children.add(new image { source = image, }); layout.children.add(new label { horizontaloptions = layoutoptions.centerandexpand, verticaloptions = layoutoptions.endandexpand, text = text, scale = 2, }); this.content = layout; } }
i able make work around problem hard coding page indicators changing carouselchild method below:
public carouselchild(string image, string text, int pagenumber, int pagecount) { var width = this.width; stacklayout layout = new stacklayout { horizontaloptions = layoutoptions.fillandexpand, verticaloptions = layoutoptions.fillandexpand, padding = new thickness( 40, 40, 40, 40), backgroundcolor = color.black, }; layout.children.add(new image { source = image, verticaloptions = layoutoptions.start, horizontaloptions = layoutoptions.center, }); layout.children.add(new label { horizontaloptions = layoutoptions.centerandexpand, text = text, fontsize = 36, linebreakmode = linebreakmode.wordwrap, }); layout.children.add(carouselpageindicator(pagenumber, pagecount)); this.content = layout; } internal stacklayout carouselpageindicator(int pagenumber, int pagecount) { stacklayout layout = new stacklayout { orientation = stackorientation.horizontal, horizontaloptions = layoutoptions.centerandexpand, verticaloptions = layoutoptions.endandexpand, }; if (pagecount >= pagenumber) { (int = 1; < pagecount + 1; i++) { if (i == pagenumber) { layout.children.add(new image { source = "light.png", }); } else { layout.children.add(new image { source = "dark.png", }); } } } return layout; }
Comments
Post a Comment