Thomas Salandre
Thomas Salandre

Reputation: 837

WP7 How to change the color of the second header of a pivot item

Is it possible to have the foreground of the header of a panorama control in red and the other title (that we can start to see because it's a pivot item) in grey for example ?

Title 1 : in red and the shaded title2 in grey.

Thank you

Upvotes: 0

Views: 2243

Answers (2)

Yugy
Yugy

Reputation: 350

You can wirte the xaml file like this:

    <controls:Pivot Title="My application" Foreground="Red">
        <controls:PivotItem>
            <controls:PivotItem.Header>
                <TextBlock Text="first" Foreground="Gray"></TextBlock>
            </controls:PivotItem.Header>
            <TextBlock Text="content"></TextBlock>
        </controls:PivotItem>
    </controls:Pivot>

Upvotes: 1

Paul Diston
Paul Diston

Reputation: 3294

You could use the SelectionChanged event handler. If you define your Headers as TextBlocks :-

                <controls:Pivot Title="MY APPLICATION"
                    SelectionChanged="Pivot_SelectionChanged">
        <controls:PivotItem>
            <controls:PivotItem.Header>
                <TextBlock Text="first"
                           Foreground="Red" />
            </controls:PivotItem.Header>
        </controls:PivotItem>
        <controls:PivotItem>
            <controls:PivotItem.Header>
                <TextBlock Text="second"
                           Foreground="Red" />
            </controls:PivotItem.Header>
        </controls:PivotItem>
        <controls:PivotItem>
            <controls:PivotItem.Header>
                <TextBlock Text="third"
                           Foreground="Red" />
            </controls:PivotItem.Header>
        </controls:PivotItem>
        <controls:PivotItem>
            <controls:PivotItem.Header>
                <TextBlock Text="fourth"
                           Foreground="Red" />
            </controls:PivotItem.Header>
        </controls:PivotItem>
    </controls:Pivot>

You can then alter the Foreground of the TextBlocks, in the C# code behind :-

        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);
            }
        }
    }

Upvotes: 1

Related Questions