Trying to rewrite machine generated my first ever WP7 HelloWorld into something more sophisticated.
Just can't understand how to get reference to objects? For instance in my layout there are several objects:
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Loaded="onLoaded"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"></Grid>
</Grid>
Simply I want to have programmatic reference to TextBlock
's. For sure it should be something very simple and obvious, but I can't find way to that.
Please give me some hint!
barmaley,
If you want to reference a control in code, you must ensure that your xaml control has its name parameter set, so for instance
<TextBlock Text="Hello World"/>
you would not be able to access that textblock very easily from the code behind, so instead you should give it a name
<TextBlock Text="Hello World" x:Name="helloWorldText"/>
therefore in your code behind you can reference this control using
helloWorldText.text = "something";
Simply use Name: ApplicationTitle
, PageTitle
...