2

我有这个:

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

但是 Foreground="{Binding}" 不起作用。我怎样才能做到这一点?谢谢!!

4

1 回答 1

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));
        }
    }
}
于 2014-08-20T12:36:54.783 回答