xaml - WP programmatically reference TextBlock in C# -


i trying disable visibility of textblock. can reference textblock in following example:

xaml file

<phone:pivotitem header="pivot 1">    <textblock text="hello world" x:name="dummytext" /> </phone:pivotitem> 

cs file

dummytext.visibility = visibility.collapsed; 

but can't reference when have following code:

xaml file

<phone:pivotitem header="{binding dummy.title}">   <grid margin="0,0,-12,0">     <listbox x:name="box1">       <phone:longlistselector itemssource="{binding dummy.items}">         <phone:longlistselector.itemtemplate>           <datatemplate>             <stackpanel>                <grid>                 //reference textblock                 <textblock text="hello world" x:name="dummytext" />               </grid>                <grid>                 <textblock text="byee world" x:name="dummytext2" />                 <textblock text="bye2 world" x:name="dummytext3" />               </grid>              </stackpanel>           </datatemplate>         </phone:longlistselector.itemtemplate>       </phone:longlistselector>     </listbox>   </grid> </phone:pivotitem> 

i new windows phone development , still learning. can point me going wrong?

if trying set visibility of control, suitable approach use visibility “converter”, send property in entity converter , return desired visibility state.

 public class visibilityconverter : ivalueconverter {     public object convert(object value, type targettype, object parameter, cultureinfo culture)     {         bool visible;          bool.tryparse(value.tostring(), out visible);          return visible ? visibility.visible : visibility.collapsed;     }      public object convertback(object value, type targettype, object parameter, cultureinfo culture)     {         throw new notimplementedexception();     } } 

define converter

you can place in app.xaml file whole app has access when required.

<application  xmlns:converters="clr-namespace:namespaceofyourconverter;assembly=assemplyofyourconverter">    <application.resources>     <resourcedictionary>         <converters:visibilityconverter x:key="visibilityconverter" />     </resourcedictionary>    </application.resources> </application> 

set xaml

<textblock text="hello world" x:name="dummytext" visibility="{binding isvisible, converter={staticresource visibilityconverter}}" /> 

see converters or bing "value converters wp8" more on creating converters


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -