Where are my WP7 objects?

Go To StackoverFlow.com

1

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!

2012-04-05 15:20
by barmaley
If it's anything like WPF, you should be able to access them in the code behind by using their names. I.e. ApplicationTitle and PageTitle - Matt Burland 2012-04-05 15:24
You're using WPF, which uses XAML for the markup. You ought to follow some tutorials on those subjects : - TJHeuvel 2012-04-05 15:25


2

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";
2012-04-05 22:52
by John Antony Daniel Nolan
Thanx, I've figured. Starting to hate VS and C# (where's my Java! - barmaley 2012-04-06 05:07


3

Simply use Name: ApplicationTitle, PageTitle...

2012-04-05 15:23
by Pol
Ads