Data binding in pivot TitleTemplate for Windows Phone

I need to skip something simple here ... I am writing a Windows Phone 7 application, and I configured my summary header as follows:

<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 go to this page, I pass Station and Location as parameters, and in OnNavigatedTo () for this page I am trying to set StationTitle and LocationTitle. Unfortunately, I get:

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

How do we do / access members in the Pivot TitleTemplate? Any help would be appreciated! Thanks.

+4
source share
3 answers

Stop using the header template and binding to it. 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 encoded: -

  if (NavigationContext.QueryString.TryGetValue("Station", out station)) { StationTitle.Text = station; } if (NavigationContext.QueryString.TryGetValue("LocationTitle", out locationTitle)) { LocationTitle.Text = locationTitle; } 
+5
source

Without looking at all the code, it can be as simple as making the name declaration consistent on your two text blocks.

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

+1
source

Defining an inline template for me, The TitleTemplate just won't work.

 <phone:Pivot> <phone:Pivot.Title> <TextBlock Margin="0" Text="{Binding Exercise.Name}" Style="{StaticResource MainTitleStyle}"/> </phone:Pivot.Title> </phone:Pivot> 
0
source

Source: https://habr.com/ru/post/1335797/


All Articles