c# - UWP Template 10 create a dynamic hamburgermenu -


i'm pretty noob uwp stuff. i'm trying create dynamic hamburger menu. able create primarybuttons element, , binding in xaml worked espected:

var loginbutton = new hamburgerbuttoninfo(); loginbutton.clearhistory = true; loginbutton.pageparameter = ""; loginbutton.pagetype = typeof(views.login); var stackpanel = new stackpanel { orientation = orientation.horizontal }; stackpanel.children.add(new symbolicon { symbol = symbol.contact, width = 48, height = 48 }); stackpanel.children.add(new textblock { text = "login", verticalalignment = verticalalignment.center, margin = new thickness(12, 0, 0, 0) }); loginbutton.content = stackpanel; 

but i'd have cleaner solution, tried extend hamburgerbuttoninfo class:

class menuitem : hamburgerbuttoninfo {     private symbol symbol;     private string text;     stackpanel stackpanel = new stackpanel { orientation = orientation.horizontal };     textbox textbox = new textbox { verticalalignment = verticalalignment.center, margin = new thickness(12, 0, 0, 0) };     symbolicon symbolicon = new symbolicon { width = 48, height = 48 };      public menuitem():base()     {         stackpanel.children.add(symbolicon);         stackpanel.children.add(textbox);         this.content = stackpanel;     }      public string text     {         { return text; }         set {             textbox.text = value;             set(ref text, value);         }     }      public stackpanel stackpanel     {         { return stackpanel; }     }      public symbol symbol     {         { return symbol; }         set {             symbolicon.symbol = value;             set(ref symbol, value);         }     } } 

putting together, expected same result:

primarybuttons.add(loginbutton); primarybuttons.add(new menuitem() { pagetype=typeof(views.login), pageparameter="", clearhistory=true, text="login", symbol=symbol.contact }); 

but here's result

enter image description here

am missing something? right approach scenario?

can done? absolutely.

var stackpanel = new stackpanel {     orientation = orientation.horizontal }; stackpanel.children.add(new symbolicon {     width = 48,     height = 48,     symbol = symbol.unsyncfolder }); stackpanel.children.add(new textblock {     margin = new thickness(12, 0, 0, 0),     verticalalignment = verticalalignment.center,     text = "unsync folder" }); var button = new hamburgerbuttoninfo {     content = stackpanel,     buttontype = hamburgerbuttoninfo.buttontypes.toggle,     clearhistory = false,     pagetype = typeof(views.detailpage) }; myhamburgermenu.primarybuttons.add(button); 

looks (i tried in search sample).

enter image description here

it's more verbose because xaml syntax compact, can in code-behind if want to. might want change visibility of existing button if option.

best of luck!


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -