windows 8.1 - x:Name doesn't work in XAML Flyout control -
i tried following in windows 8.1 c# app:
<!-- xaml file --> <page.bottomappbar> <commandbar> <appbarbutton label="add news feed" icon="add"> <appbarbutton.flyout> <flyout> <stackpanel width="400"> <textblock textwrapping="wrap" text="enter text:" margin="0,0,0,10"/> <textbox x:name="inputtextbox"/> <button content="add" horizontalalignment="right" verticalalignment="stretch" click="addbutton_click"/> </stackpanel> </flyout> </appbarbutton.flyout> </appbarbutton> </commandbar> </page.bottomappbar>
// c# file private void addbuton_click(object sender, windows.ui.xaml.routedeventargs e) { var text = inputtextbox.text; // text }
however, when run app , click add button system.nullreferenceexception because member inputtextbox null. checked , generated initializecomponent method has following line:
inputtextbox = (global::windows.ui.xaml.controls.textbox)this.findname("inputtextbox");
i tried changing event handler call findname in case control created when flyout shown , still returns null. why can't findname find text box?
update: workaround
i able textbox using visualtreehelper shown below:
textbox textbox = null; var parent = visualtreehelper.getparent(sender button); var numchildren = visualtreehelper.getchildrencount(parent); (var = 0; < numchildren; ++i) { var child = visualtreehelper.getchild(parent, i) frameworkelement; if (child != null && child.name == "inputtextbox") { // found text box! textbox = child textbox; break; } } if (textbox != null) { var text = textbox.text; // text }
if indeed confirmed bug in windows 8.1 preview i'll go ahead , close out question.
this issue 8.1 preview , hope have issue addressed in final version of 8.1
joe
Comments
Post a Comment