2012-11-27 32 views
2

我有这样的:需要更改标题支点项目的前景色动态

<controls:Pivot.HeaderTemplate> 
    <DataTemplate> 
     <ContentPresenter> 
      <TextBlock Text="{Binding}" Foreground="{Binding}" /> 
     </ContentPresenter> 
    </DataTemplate> 
</controls:Pivot.HeaderTemplate> 

但前景=“{结合}”是行不通的。我怎样才能做到这一点? 谢谢!

+0

相关? http://stackoverflow.com/questions/4245046/change-background-of-title-and-header-in-pivot-control –

回答

0

你可以做到这一点与后面的代码:

XAML:

<Pivot x:Uid="AppTitle" x:Name="MyPivot" Title="" Foreground="White"> 
    <PivotItem> 
     <PivotItem.Header> 
      <TextBlock x:Uid="HeaderTextFromResources" Foreground="White" Text="" /> 
     </PivotItem.Header> 
    ... 

C#:

private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
    foreach (PivotItem pivotItem in MyPivot.Items) 
    { 
     if (pivotItem == MyPivot.Items[MyPivot.SelectedIndex]) 
     { 
      // Header of the selected item to white 
      ((TextBlock)pivotItem.Header).Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 255, 255, 255)); 
     } 
     else 
     { 
      // Headers of other items to slightly darker 
      ((TextBlock)pivotItem.Header).Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 230, 230, 230)); 
     } 
    } 
} 
+0

但是这不会工作,如果你使用ItemsSource = {绑定..}因为pivotItem将是任何类型。 –