2

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>

2 Answers2

6

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>

-1

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!

Community
  • 1
  • 1
Kulasangar
  • 9,046
  • 5
  • 51
  • 82
  • In selection changed We can write But I want write in Visual States of Selected And UnSelected can You help me to write the visual states of Selected And Un Selected States – Harish Kinthali Jun 23 '14 at 10:53
  • @HarishKinthali the link which I've provide you above talks about visual states only. – Kulasangar Jun 23 '14 at 10:55
  • 1
    it is for Windows Phone 8 i'm working on Windows Phone 8.1,It was working in windows 8 but not in windows 8.1 – Harish Kinthali Jun 23 '14 at 11:00