4

I must be missing something simple here...I am writing a Windows Phone 7 app and I have customized my pivot header to be the following:

<controls:Pivot Name="InfoPivot">
  <controls:Pivot.TitleTemplate>
    <DataTemplate>
      <StackPanel Orientation="Horizontal" Margin="0,0,0,0" VerticalAlignment="Top">
        <Rectangle Fill="{Binding CategoryFill}"  Height="50" Width="50" Margin="355,25,0,0" HorizontalAlignment="Left"  VerticalAlignment="Top" Name="CategoryRect" />
        <StackPanel Margin="-425,-14,0,0" Width="432">
          <TextBlock x:Name="StationTitle" Text="{Binding StationTitle}" Margin="10,0,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
          <TextBlock Name="LocationTitle" Text="{Binding LocationTitle}" TextWrapping="Wrap" Margin="12,0,0,20" Style="{StaticResource PhoneTextNormalStyle}"/>
         </StackPanel>
       </StackPanel>
     </DataTemplate>
   </controls:Pivot.TitleTemplate>

When I navigate to this page, I pass Station and Location as parameters, and in the OnNavigatedTo() for this page I try to set the StationTitle and LocationTitle. Unfortunately, I end up getting:

Error 2 The name 'StationTitle' does not exist in the current context

How should/do we go about accessing members in the Pivot TitleTemplate? Any help will be appreciated! Thanks.

Praetorian
  • 106,671
  • 19
  • 240
  • 328
Shawn
  • 41
  • 1
  • 2
  • Hi Shawn, Could you show us how you're declaring/passing the parameters? – Mick N Jan 17 '11 at 06:24
  • From MainPage.xml in a SelectionChangedHandler: NavigationService.Navigate(new Uri("/TestInfoPivot.xaml?" + "Station=" + stationStr + "&Location=" + locationStr, UriKind.Relative)); I have verified that stationStr and locationStr has the correct values....then in TestInfoPivot.xaml I do string station = ""; if (NavigationContext.QueryString.TryGetValue("Station", out station)) { StationTitle = station; } similar for LocationTitle. – Shawn Jan 17 '11 at 06:47
  • Do you see the correct values in StationTitle and LocationTitle after the QueryString code in TestInfoPivot executes? Hard to get a sense of this without seeing the blocks of code - it would be preferable if you could paste them into an edit of the original question. – Mick N Jan 17 '11 at 07:55
  • When Providing additional details please edit you question rather placing them in a comment. This is especially true when those details contain code because as you can see the code is barely readable a comment. – AnthonyWJones Jan 17 '11 at 13:24

3 Answers3

5

Stop using the title template and binding to acheive this. Try this instead:-

<controls:Pivot Name="InfoPivot">
   <controls:Pivot.Title>
       <StackPanel Orientation="Horizontal" Margin="0,0,0,0" VerticalAlignment="Top">
          <Rectangle Fill="{Binding CategoryFill}" Height="50" Width="50" Margin="355,25,0,0" HorizontalAlignment="Left"  VerticalAlignment="Top" Name="CategoryRect" />
          <StackPanel Margin="-425,-14,0,0" Width="432">
              <TextBlock x:Name="StationTitle" Margin="10,0,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
              <TextBlock x:Name="LocationTitle" TextWrapping="Wrap" Margin="12,0,0,20" Style="{StaticResource PhoneTextNormalStyle}"/> 
          </StackPanel>
        </StackPanel>
   </controls:Pivot.Title>

Then in code-behind:-

 if (NavigationContext.QueryString.TryGetValue("Station", out station))
 {
     StationTitle.Text = station;
 }

 if (NavigationContext.QueryString.TryGetValue("LocationTitle", out locationTitle))
 {
     LocationTitle.Text = locationTitle;
 }
AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
1

Without seeing all of your code, this may be as simple as making the Name declaration consistent on your two TextBlocks.

Note, one is Name="", the other is x:Name="".

Mick N
  • 14,892
  • 2
  • 35
  • 41
0

Defining the template inline worked for me, The TitleTemplate just wouldn't work.

<phone:Pivot>
    <phone:Pivot.Title>
        <TextBlock Margin="0"
            Text="{Binding Exercise.Name}" 
            Style="{StaticResource MainTitleStyle}"/>
    </phone:Pivot.Title>
</phone:Pivot>
Ryan
  • 353
  • 1
  • 7