我有这个:
<controls:Pivot.HeaderTemplate>
<DataTemplate>
<ContentPresenter>
<TextBlock Text="{Binding}" Foreground="{Binding}" />
</ContentPresenter>
</DataTemplate>
</controls:Pivot.HeaderTemplate>
但Foreground =“{Binding}”无效。我怎样才能做到这一点? 谢谢!
答案 0 :(得分: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));
}
}
}