Windows Phone 8.1 ,如何自定义Pivot头部样式?用Pivot控件完成这样的效果。

网上找了好久,只找到了windows phone 8的解决方案。 终于一个大神给支了招,我觉得我有必要跟诸位开发者分享一下经验。Windows Phone 8.1的开发资料实在太少了。我决定,用一个假期把我知道的都分享出来。

如果,你支持我的做法。请点赞或者评论本条博客、或者去 windows phone 应用商店 下载一个叫【有点意思】的app、再或者遥祝大黑兔减肥成功。 大黑兔将非常高兴。有点意思:http://www.windowsphone.com/zh-cn/store/app/%e6%9c%89%e7%82%b9%e6%84%8f%e6%80%9d/f2e705b4-5fd6-4c69-826b-c2f05c825ef0

好了,扯淡结束,开始工作。

1. 在App.xaml里定义自己的Pivot控件样式。下面的代码加在Application.Resources节点下,这样你的每一个页面就都能用到这个样式了。

 <Style TargetType="Pivot">

     <Setter Property="Template">

         <Setter.Value>

             <ControlTemplate TargetType="Pivot">

                 <Grid 

                     x:Name="RootElement" 

                     HorizontalAlignment="{TemplateBinding HorizontalAlignment}"

                     VerticalAlignment="{TemplateBinding VerticalAlignment}"

                     Background="{TemplateBinding Background}">

                     <VisualStateManager.VisualStateGroups>

                         <VisualStateGroup x:Name="Orientation">

                             <VisualState x:Name="Portrait">

                                 <Storyboard>

                                     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="TitleContentControl" Storyboard.TargetProperty="Margin">

                                         <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource PivotPortraitThemePadding}" />

                                     </ObjectAnimationUsingKeyFrames>

                                 </Storyboard>

                             </VisualState>

                             <VisualState x:Name="Landscape">

                                 <Storyboard>

                                     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="TitleContentControl" Storyboard.TargetProperty="Margin">

                                         <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource PivotLandscapeThemePadding}" />

                                   </ObjectAnimationUsingKeyFrames>

                               </Storyboard>

                           </VisualState>

                       </VisualStateGroup>

                   </VisualStateManager.VisualStateGroups>

                   <Grid.RowDefinitions>

                               <RowDefinition Height="Auto" />

                               <RowDefinition Height="*" />

                           </Grid.RowDefinitions>

                   <Border Background="Red">

                       <ContentControl x:Name="TitleContentControl"

                                       Style="{StaticResource PivotTitleContentControlStyle}"

                                       Content="{TemplateBinding Title}"

                                       ContentTemplate="{TemplateBinding TitleTemplate}"/>

                   </Border>

                   <ScrollViewer

                       x:Name="ScrollViewer"

                       Margin="{TemplateBinding Padding}"

                       Grid.Row="1"

                       HorizontalSnapPointsType="MandatorySingle"

                       HorizontalSnapPointsAlignment="Center"

                       HorizontalScrollBarVisibility="Hidden"

                       VerticalScrollMode="Disabled"

                       VerticalScrollBarVisibility="Disabled"

                       VerticalSnapPointsType="None"

                       VerticalContentAlignment="Stretch"

                       ZoomMode="Disabled"

                       Template="{StaticResource ScrollViewerScrollBarlessTemplate}">

                       <PivotPanel x:Name="Panel" VerticalAlignment="Stretch">

                           <PivotHeaderPanel x:Name="Header" Background="Red">

                               <PivotHeaderPanel.RenderTransform>

                                   <CompositeTransform x:Name="HeaderTranslateTransform" TranslateX="0" />

                               </PivotHeaderPanel.RenderTransform>

                           </PivotHeaderPanel>

                           <ItemsPresenter x:Name="PivotItemPresenter">

                               <ItemsPresenter.RenderTransform>

                                   <TranslateTransform x:Name="ItemsPresenterTranslateTransform" X="0" />

                               </ItemsPresenter.RenderTransform>

                           </ItemsPresenter>

                       </PivotPanel>

                   </ScrollViewer>

               </Grid>

           </ControlTemplate>

       </Setter.Value>

   </Setter>

 </Style>

2.在调用Pivot的页面中定义,primitives的namespace,加入以下代码。

xmlns:primitives="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone"

3.在要使用Pivot的页面里,给Pivot指定这个样式:

<Pivot Style="{StaticResource DiaosbookPivotStyle}">
 
等等别走,点个赞再走~

WP8.1 Windows Phone 8.1开发:何如定义Pivot头部样式、定义Pivot头部颜色的更多相关文章

  1. Windows Phone 8.1 开发技术概览 (Universal APP)

    前一阵真的比较懒 WP8.1 已经出来这么长时间了现在才更新BLOG让大家久等了,今天我先为大家介绍下 WP 8.1的开发框架,什么是微软所推崇的 Universal APP,以及我们要开发 Univ ...

  2. windows phone 8.1开发SQlite数据库操作详解

    原文出自:http://www.bcmeng.com/windows-phone-sqlite1/ 本文小梦将和大家分享WP8.1中SQlite数据库的基本操作:(最后有整个示例的源码)(希望能通过本 ...

  3. 课程上线 -“新手入门 : Windows Phone 8.1 开发”

    经过近1个月的准备和录制,“新手入门 : Windows Phone 8.1 开发”系列课程已经在Microsoft 虚拟学院上线,链接地址为:http://www.microsoftvirtuala ...

  4. Windows下USB磁盘开发系列二:枚举系统中所有USB设备

    上篇 <Windows下USB磁盘开发系列一:枚举系统中U盘的盘符>介绍了很简单的获取系统U盘盘符的办法,现在介绍下如何枚举系统中所有USB设备(不光是U盘). 主要调用的API如下: 1 ...

  5. Windows平台下PHP开发环境的配置

    Windows平台下PHP开发环境的配置 一.基本环境 1.Windows XP 32位 2.Apache 2.2.25,下载地址:http://mirror.bit.edu.cn/apache/ht ...

  6. 《深入浅出Windows 10通用应用开发》

        <深入浅出Windows 10通用应用开发>采用Windows 10的SDK进行重新改版,整合了<深入浅出Windows Phone 8.1应用开发>和<深入解析 ...

  7. 2013-6-2 [转载自CSDN]如何入门Windows系统下驱动开发

    [序言]很多人都对驱动开发有兴趣,但往往找不到正确的学习方式.当然这跟驱动开发的本土化资料少有关系.大多学的驱动开发资料都以英文为主,这样让很多驱动初学者很头疼.本人从事驱动开发时间不长也不短,大概 ...

  8. Windows下搭建Git开发环境

    Windows下搭建Git开发环境主要有以下三种方法: 1,VS,vs2013和vs2015中已经集成了git插件了 2,msysGit+TortoiseGit 3,msysGit+SourceTre ...

  9. windows环境下Eclipse开发MapReduce程序遇到的四个问题及解决办法

    按此文章<Hadoop集群(第7期)_Eclipse开发环境设置>进行MapReduce开发环境搭建的过程中遇到一些问题,饶了一些弯路,解决办法记录在此: 文档目的: 记录windows环 ...

随机推荐

  1. Spring学习(二)—— java的动态代理机制

    在学习Spring的时候,我们知道Spring主要有两大思想,一个是IoC,另一个就是AOP,对于IoC,依赖注入就不用多说了,而对于Spring的核心AOP来说,我们不但要知道怎么通过AOP来满足的 ...

  2. TCP系列13—重传—3、协议中RTO计算和RTO定时器维护

    从上一篇示例中我们可以看到在TCP中有一个重要的过程就是决定何时进行超时重传,也就是RTO的计算更新.由于网络状况可能会受到路由变化.网络负载等因素的影响,因此RTO也必须跟随网络状况动态更新.如果T ...

  3. redis切换数据库的方法【jedis】

    package com.test; import redis.clients.jedis.Jedis; public class readredis { public static void main ...

  4. Python使用ElementTree美化XML格式

    Python中使用ElementTree可以很方便的处理XML,但是产生的XML文件内容会合并在一行,难以看清楚. 如下格式: <root><aa>aatext<cc&g ...

  5. wine update错误 "the cache has no package" error when wine update is available

    网址:https://bugs.launchpad.net/pipelight/+bug/1318321/

  6. 第三部分shell编程3(shell脚本2)

    7. if 判断一些特殊用法 if [ -z $a ] 这个表示当变量a的值为空时会怎么样if grep -q '123' 1.txt; then 表示如果1.txt中含有'123'的行时会怎么样if ...

  7. 加密和数字签名工具GPG

    转载: 源文件位置:http://blog.chinaunix.net/uid-9525959-id-2001824.html GPG [功能]  GPG是加密和数字签名的免费工具,大多用于加密信息的 ...

  8. Python 时间推进器-->在当前时间的基础上推前n天 | CST时间转化标准日期格式

    由于公司任务紧迫,好久没有在园子里写自己的心得了,今天偷个闲发表点简单的代码块,在开源的时代贡献微薄力量.话不多说,直接上代码块: ]) m = ]) d = ]) the_date = dateti ...

  9. EasyUI 学习笔记

    EasyUI常见错误 1 . 无论是用HMTL形式实现组件还是使用代码 + HTML 形式实现组件 , 在为组件设置属性时 , 要注意属性值的类型问题 string:必须加引号 number:不加任何 ...

  10. Matlab 函数ndims简介,flipdim简介

    ndims是matlab中求一个数组维数的函数. 调用格式: n=ndims(A) 将A的维数返回给变量n.n>=2 n=ndims(A)与n=length(size(A))是等价的 MATLA ...