c# - Windows Phone 8 XAML Editor setting variables to null at runtime -


i've been trying add simple textblock control windows phone 8 app, once assign name in gui xaml editor , attempt access control via assigned name in c# code @ runtime "nullreferenceexceptions" because variable never set. have narrowed problem down phoneapplicationpage method "findname" i.e.

phoneapplicationpage.findname("videoname"); 

however call of controls (created in gui editor) return null. has had problem , found fix?

regards.

the contents of initialisecomponent() method:

 public void initializecomponent() {         if (_contentloaded) {             return;         }         _contentloaded = true;         system.windows.application.loadcomponent(this, new system.uri("/youtube%20downloader;component/mainpage.xaml", system.urikind.relative));         this.layoutroot = ((system.windows.controls.grid)(this.findname("layoutroot")));         this.titlepanel = ((system.windows.controls.stackpanel)(this.findname("titlepanel")));         this.contentpanel = ((system.windows.controls.grid)(this.findname("contentpanel")));         this.videoname = ((system.windows.controls.textblock)(this.findname("videoname")));         this.videoimage = ((system.windows.controls.image)(this.findname("videoimage")));     } 

(the videoname , videoimage controls ones not getting added)

the xaml code (that editor has generated):

 <phone:phoneapplicationpage x:class="youtube_downloader.mainpage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:microsoft.phone.controls;assembly=microsoft.phone" xmlns:shell="clr-namespace:microsoft.phone.shell;assembly=microsoft.phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:ignorable="d" fontfamily="{staticresource phonefontfamilynormal}" fontsize="{staticresource phonefontsizenormal}" foreground="{staticresource phoneforegroundbrush}" supportedorientations="portrait" orientation="portrait" shell:systemtray.isvisible="true">  <grid x:name="layoutroot" background="transparent">     <grid.rowdefinitions>         <rowdefinition height="auto"/>         <rowdefinition height="*"/>     </grid.rowdefinitions>      <stackpanel x:name="titlepanel" grid.row="0" margin="12,17,0,28">         <textblock text="youtube downloader" style="{staticresource phonetextnormalstyle}" margin="12,0"/>     </stackpanel>      <!--contentpanel - place additional content here-->     <grid x:name="contentpanel" grid.row="1" margin="12,0,12,0">         <textblock x:name="videoname" margin="10,10,0,0" textwrapping="wrap" text="textblock" verticalalignment="top" height="56" fontsize="36" fontstyle="normal"/>         <image x:name="videoimage" horizontalalignment="center" height="408" margin="0,72,0,0" verticalalignment="top" width="446"/>     </grid> </grid> 

i had same problem. clean project fix it.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -