简体   繁体   中英

change the backgorund of the pivot item in windows phone 8

I have a style

  <Style x:Key="PivotStyle1" TargetType="phone:Pivot">
        <Setter Property="Margin" Value="0"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <Grid/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="phone:Pivot">
                    <Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>                           
                        <Grid Background="{TemplateBinding Background}" CacheMode="BitmapCache"  Grid.RowSpan="3"/>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Image
                                Height="45"
                                HorizontalAlignment="Left"
                                Margin="12,0,0,0"
                                VerticalAlignment="Bottom"
                                Source="/Assets/Icons/MyTasks.png" />
                            <ContentControl
                                ContentTemplate="{TemplateBinding TitleTemplate}"
                                Content="{TemplateBinding Title}"
                                Grid.Column="1"
                                HorizontalAlignment="Left"
                                Margin="10,0,0,-7"
                                VerticalAlignment="Center"
                                Style="{StaticResource PivotTitleStyle}"/>
                            <Image
                                Grid.Column="2"
                                Height="55" Margin="0,10,20,0"
                                HorizontalAlignment="Right"
                                VerticalAlignment="Bottom"
                                Source="/Assets/Icons/Settings.png"/>
                        </Grid>
                        <Primitives:PivotHeadersControl x:Name="HeadersListElement" Grid.Row="1"/>
                        <ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}"
                                        Grid.Row="2"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

This is my pivot code:

 <phone:Pivot Title="MY TASKS" Style="{StaticResource PivotStyle1}" >

        <!--Pivot item one-->
        <phone:PivotItem Header="all">               

        </phone:PivotItem>

        <phone:PivotItem Header="assigned">

        </phone:PivotItem>

        <phone:PivotItem Header="overdue">

        </phone:PivotItem>
    </phone:Pivot>

I want to change the color of pivot items. pivot item header "all" in red color, pivot item "assigned" in green color. I have tried to change the background, but that changes the full background. please suggest.

This one worked for me.

 <phone:PivotItem>
            <phone:PivotItem.Header>
                <TextBlock Text="assigned" Foreground="#FF145377"></TextBlock>
            </phone:PivotItem.Header>
        </phone:PivotItem>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM