更改Windows Phone 8中枢轴项的背景

时间:2013-10-29 10:35:13

标签: c# xaml windows-phone-8

我有一种风格

  <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>

这是我的透视代码:

 <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>

我想更改枢轴项目的颜色。枢轴项标题“全部”为红色,枢轴项目“已分配”为绿色。我试图改变背景,但这会改变整个背景。请建议。

1 个答案:

答案 0 :(得分:0)

这个对我有用。

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