Harish Kinthali
Harish Kinthali

Reputation: 75

Pivot Item Header Coulor Change opacity of all Headers Remains Same in windows Phone 8.1 Pivot Control

I am working on Pivot Control in Windows Phone 8.1 I Set foreground Property of pivotitem Header to Red Color it is working Fine but,I set all items header to Red Color and the Opacity of the Item Header Never Changes of UnFocused PivotItem cloud Please Help me how to solve this
Problem. Here is the code

   <Pivot Title="Pivot Title" >
        <PivotItem >
            <PivotItem.Header >
                <TextBlock Text="One" Foreground="Red" FontSize="48"/>
            </PivotItem.Header>
        </PivotItem>
        <PivotItem>
            <PivotItem.Header>
                <TextBlock Text="two" Foreground="Red" FontSize="48"/>
            </PivotItem.Header>
        </PivotItem>
        <PivotItem>
            <PivotItem.Header>
                <TextBlock Text="three" Foreground="Red" FontSize="48"/>
            </PivotItem.Header>
        </PivotItem>
    </Pivot>

Upvotes: 2

Views: 2018

Answers (2)

Harish Kinthali
Harish Kinthali

Reputation: 75

The Default Styles Should be over ridden in Resource Dictionary <ResourceDictionary.ThemeDictionaries> <ResourceDictionary x:Key="Default"> <SolidColorBrush x:Key="PivotHeaderForegroundUnselectedBrush" Color="#AFAFAF" /> <SolidColorBrush x:Key="PivotHeaderForegroundSelectedBrush" Color="#56C5FF" /> </ResourceDictionary> </ResourceDictionary.ThemeDictionaries>

Upvotes: 6

Kulasangar
Kulasangar

Reputation: 9464

I guess you'll need to set a different VisualState for either the Selected or Unselected state.

Have a look over here How to Change Pivot Header Template in Windows Phone 8

Or you could use the SelectionChanged event handler for your pivot:

private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (e.AddedItems.Count > 0)
    {
        PivotItem currentItem = e.AddedItems[0] as PivotItem;

        if (currentItem != null)
        {
            (currentItem.Header as TextBlock).Foreground = new SolidColorBrush(Colors.White);
        }
    }

    if (e.RemovedItems.Count > 0)
    {
        PivotItem currentItem = e.RemovedItems[0] as PivotItem;

        if (currentItem != null)
        {
            (currentItem.Header as TextBlock).Foreground = new SolidColorBrush(Colors.Red);
        }
    }
}

Hope it helps!

Upvotes: -1

Related Questions