Reputation: 1046
I am creating a Windows Store Blank application. Following is my code:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition Height="700"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="Sample Search Application" Margin="30" FontSize="36" />
<StackPanel Grid.Row="1" Orientation="Horizontal">
<TextBox x:Name="txtsearch" Width="200" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="30" TextChanged="txtsearch_TextChanged"></TextBox>
<Button x:Name="BtnPrint" Content="GetValue" Click="BtnPrint_Click"></Button>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal">
<TextBlock x:Name="Result" FontSize="36"></TextBlock>
</StackPanel>
</Grid>
As you see that I have defined a textbox. But in the cs file I am unable to access this textblock. Following is my cs file snapshot:
Upvotes: 0
Views: 178
Reputation: 222582
You need to define the TextBlock name,
<TextBlock Name="txtTest" Text="Flickr Search Application" Margin="30" FontSize="36" />
EDIT:
Since you have TextBlock inside a parent control, you can use FindName
method.
Upvotes: 2