Instantiating XAML UIElement using C# -
i want make on windows phone, have been googling "instantiating uielement in c#", can't seem find can me..
what want :-
1) user press button
2) program instantiate new grid/stackpanel textblock in it.
is there link me refer?
firstly, need add click event button.
<button click="dosomethingamazing" .../> and in c# code behind, can create grid, , add textblock.
private void dosomethingamazing(object sender, routedeventargs e) { grid grd = new grid(); textblock txt = new textblock() { text = "wow!" }; grd.children.add(txt); //add grid window/page/usercontrol this.addchild(grd); } the code add child parent may differ depending on platform on, think idea.
that being said, shouldn't instantiating controls in code-behind, instead, should declare them in xaml, , in case @ least, use visibility show/hide controls.
xaml there reason, embrace it.
Comments
Post a Comment