在枢轴控件中更改标题和标题的背景 [英] Change background of title and header in pivot control

查看:25
本文介绍了在枢轴控件中更改标题和标题的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Phone 7 应用程序中,我使用了一个枢轴控件.现在我想更改其标题和标题区域的背景.我怎样才能做到这一点?

In my Phone 7 application, I'm using a pivot control. Now I'd like to change the background of its title and header area. How can I achieve this?

是否有可以自定义的枢轴控件的整体模板?

Is there an overall template for the pivot control that can be customized?

我已经尝试将包含枢轴控件的网格的背景设置为标题颜色,然后将每个枢轴项的背景设置为原始背景颜色.第一眼看起来不错.但是,当您向左擦除枢轴项目以显示第二个项目时,两个枢轴项目之间会出现一个以标题颜色着色的区域.所以这种方法行不通.

I've already tried to set the background of the grid containing the pivot control to the header color and then to set the background of each pivot item to the original background color. It looks good on first sight. But when you wipe the pivot item to the left to display the second item, an area colored in the header color appears between the two pivot items. So that approach is not working.

此外,我尝试自定义标题和标题项的模板.但是这些模板只覆盖了文本本身的区域,而不是整个页眉和模板区域.

Furthermore I've tried to customize the template of the title and the header item. But these templates only cover the area of the text itself, not the whole header and template area.

推荐答案

这是更改控件模板的变体.将 Background="Red" 更改为您想要的任何画笔.

Here's the variant with changing the control's template. Change the Background="Red" to whatever brush you want.

<Style x:Key="PivotStyle1" TargetType="controls: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="controls:Pivot">
        <Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
              VerticalAlignment="{TemplateBinding VerticalAlignment}">
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
          </Grid.RowDefinitions>
          <Grid Background="Red" CacheMode="BitmapCache" Grid.RowSpan="2" />
          <Grid Background="{TemplateBinding Background}" CacheMode="BitmapCache"
                Grid.Row="2" />
          <ContentPresenter ContentTemplate="{TemplateBinding TitleTemplate}"
                            Content="{TemplateBinding Title}" Margin="24,17,0,-7"/>
          <controlsPrimitives:PivotHeadersControl x:Name="HeadersListElement"
                                                  Grid.Row="1"/>
          <ItemsPresenter x:Name="PivotItemPresenter"
                          Margin="{TemplateBinding Padding}" Grid.Row="2"/>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

....

<controls:Pivot Title="MY APPLICATION" Style="{StaticResource PivotStyle1}">

....

这篇关于在枢轴控件中更改标题和标题的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆