Windows phone 7 如何将透视页眉更改为页码?

Windows phone 7 如何将透视页眉更改为页码?,windows-phone-7,xaml,windows-phone-8,Windows Phone 7,Xaml,Windows Phone 8,我有一个pivot控件,项目是从列表绑定的,我想让pivot标题看起来像一个页码,像这样:(1/20)(2/20)(3/20)。。。。这是我的xaml: <Grid x:Name="LayoutRoot"> <Grid.Background> <ImageBrush ImageSource="/Images/PivotBackground.png"/> </Grid.Background>

我有一个pivot控件,项目是从列表绑定的,我想让pivot标题看起来像一个页码,像这样:(1/20)(2/20)(3/20)。。。。这是我的xaml:

<Grid x:Name="LayoutRoot">
        <Grid.Background>
            <ImageBrush ImageSource="/Images/PivotBackground.png"/>
        </Grid.Background>
        <!--Pivot Control-->
        <controls:Pivot x:Name="newsPivot" ItemsSource="{Binding LatestArticles}" Margin="0,68,0,0">
            <!--Pivot item one-->
            <controls:Pivot.HeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="1" FontSize="30" Foreground="White" TextWrapping="Wrap"/>
                </DataTemplate>
            </controls:Pivot.HeaderTemplate>
            <controls:Pivot.ItemTemplate>
                <DataTemplate>
                    <ScrollViewer>
                    <Grid>
                        <StackPanel>
                            <TextBlock Text="{Binding title}" FontSize="30" Foreground="Black" TextWrapping="Wrap" 
                                   Grid.Row="1"   
                                   Grid.Column="0"
                                   Width="425"
                                   Margin="10,0,0,0"/>
                        </StackPanel>
                        <StackPanel>
                            <Image delay:LowProfileImageLoader.UriSource="{Binding thumbnail, StringFormat='http://digitaledition.philstar.com/newsrepository/newsarticles/thumbs/images/\{0\}'}" 
                                   Margin="18,100,0,0"
                                   Grid.Column="0"
                                   Grid.Row="2"
                                   HorizontalAlignment="Left"
                                   Width="150" 
                                   Height="175"  
                                   Stretch="UniformToFill" />
                        </StackPanel>
                        <StackPanel>
                            <TextBlock Text="{Binding author, StringFormat='By \{0\}'}" TextWrapping="Wrap" FontSize="22"
                                   Grid.Column="1"
                                   Width="220"
                                   Foreground="Gray"
                                   Margin="120,135,0,0"/>
                        </StackPanel>
                        <StackPanel>
                            <TextBlock Text="{Binding dateFormatted}" TextWrapping="Wrap" FontSize="20"
                                   Grid.Column="1"
                                   Width="240"
                                   Foreground="Gray"
                                   Margin="140,210,0,0"/>
                        </StackPanel>
                        <StackPanel>
                            <TextBlock Text="{Binding content}" TextWrapping="Wrap" FontSize="24"
                                   Grid.Column="1"
                                   Width="425"
                                   Foreground="Black"
                                   Margin="10,325,0,0"/>
                        </StackPanel>
                    </Grid>
                    </ScrollViewer>
                </DataTemplate>
            </controls:Pivot.ItemTemplate>
            <!--Pivot item two-->
        </controls:Pivot>
    </Grid>

您必须将标题的文本绑定到Articles对象的属性。这个属性将是文章的页面索引

<controls:Pivot.HeaderTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding PageNumber}" FontSize="30" Foreground="White" TextWrapping="Wrap"/>
    </DataTemplate>
</controls:Pivot.HeaderTemplate>
另一个选择是使用。此选项要求您以某种方式访问最新版本

<controls:Pivot.HeaderTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding Converter={StaticResource PageNumberConverter}}" FontSize="30" Foreground="White" TextWrapping="Wrap"/>
    </DataTemplate>
</controls:Pivot.HeaderTemplate>

谢谢@ShawnKendrot,我的Latestarticles是一个存储json数据的类。在PageNumberCoverter类中如何实现这一点?您需要一个可以从应用程序中的任何位置访问的ViewModel。如果您在VisualStudio中创建一个新的“数据绑定应用程序”,您将看到这个示例。Pivot的ItemsSource将绑定到ViewModel上的属性,而您的代码隐藏将设置ViewModel的属性,而不是设置ItemsSource。不要绑定ItemsSource,因为您将在代码隐藏中覆盖它
<controls:Pivot.HeaderTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding PageNumber}" FontSize="30" Foreground="White" TextWrapping="Wrap"/>
    </DataTemplate>
</controls:Pivot.HeaderTemplate>
LatestArticles.Add(article);
article.PageNumber = LatestArticles.Count +1;
<controls:Pivot.HeaderTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding Converter={StaticResource PageNumberConverter}}" FontSize="30" Foreground="White" TextWrapping="Wrap"/>
    </DataTemplate>
</controls:Pivot.HeaderTemplate>
public class PageNumberConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        // Assumes that the App.xaml.cs class has a static ViewModel property
        return App.ViewModel.LatestArticles.IndexOf(value) + 1;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}