枢轴标题样式

2024-01-29

C# UWP Windows 10 项目

I need to set Pivot header style to something like this enter image description here

我尝试使用这个例子堆栈溢出 https://stackoverflow.com/questions/31797875/overriding-pivot-header-foreground-brushes-in-uwp-app-win-10-rtm-sdk,但没有成功。

你能说我如何在标题文本后面设置矩形(如图像上)并更改选定的未选定项目的背景颜色吗?


正如您提到的答案,我们可以使用PivotHeaderItem 样式和模板 https://msdn.microsoft.com/en-us/library/windows/apps/mt299142.aspx来实施这一点。

首先,我们可以复制样式MSDN https://msdn.microsoft.com/en-us/library/windows/apps/mt299142.aspx并放入Page.Resources.

然后添加一个Border in the Grid并设置其属性如下:

<Grid x:Name="Grid" Background="{TemplateBinding Background}">
    ...
    <Border x:Name="Border"
            BorderBrush="Gray"
            BorderThickness="2"
            CornerRadius="20">
        <ContentPresenter x:Name="ContentPresenter"
                          Margin="{TemplateBinding Padding}"
                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                          Content="{TemplateBinding Content}"
                          ContentTemplate="{TemplateBinding ContentTemplate}"
                          FontFamily="{TemplateBinding FontFamily}"
                          FontSize="{TemplateBinding FontSize}"
                          FontWeight="{TemplateBinding FontWeight}">
            <ContentPresenter.RenderTransform>
                <TranslateTransform x:Name="ContentPresenterTranslateTransform" />
            </ContentPresenter.RenderTransform>
        </ContentPresenter>
    </Border>
</Grid>

这将添加一个带有角的边框,就像您的图像一样。

之后,我们可以编辑“选定”VisualState这样当我们选择标题时,它就可以改变背景和前景:

<VisualState x:Name="Selected">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
            <DiscreteObjectKeyFrame KeyTime="0" Value="White" />
        </ObjectAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="Background">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Red" />
        </ObjectAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="BorderBrush">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Red" />
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

以下是我使用的完整 XAML:

<Page x:Class="PivotUWP.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:local="using:PivotUWP"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d">
    <Page.Resources>
        <Style TargetType="PivotHeaderItem">
            <Setter Property="FontSize" Value="{ThemeResource PivotHeaderItemFontSize}" />
            <Setter Property="FontFamily" Value="{ThemeResource PivotHeaderItemFontFamily}" />
            <Setter Property="FontWeight" Value="{ThemeResource PivotHeaderItemThemeFontWeight}" />
            <Setter Property="CharacterSpacing" Value="{ThemeResource PivotHeaderItemCharacterSpacing}" />
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
            <Setter Property="Padding" Value="{ThemeResource PivotHeaderItemMargin}" />
            <Setter Property="Height" Value="48" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="PivotHeaderItem">
                        <Grid x:Name="Grid" Margin="10,0" Background="{TemplateBinding Background}">
                            <Grid.Resources>
                                <Style x:Key="BaseContentPresenterStyle" TargetType="ContentPresenter">
                                    <Setter Property="FontFamily" Value="XamlAutoFontFamily" />
                                    <Setter Property="FontWeight" Value="SemiBold" />
                                    <Setter Property="FontSize" Value="15" />
                                    <Setter Property="TextWrapping" Value="Wrap" />
                                    <Setter Property="LineStackingStrategy" Value="MaxHeight" />
                                    <Setter Property="TextLineBounds" Value="Full" />
                                    <Setter Property="OpticalMarginAlignment" Value="TrimSideBearings" />
                                </Style>
                                <Style x:Key="BodyContentPresenterStyle" BasedOn="{StaticResource BaseContentPresenterStyle}" TargetType="ContentPresenter">
                                    <Setter Property="FontFamily" Value="{ThemeResource PivotHeaderItemFontFamily}" />
                                    <Setter Property="FontWeight" Value="{ThemeResource PivotHeaderItemThemeFontWeight}" />
                                    <Setter Property="FontSize" Value="{ThemeResource PivotHeaderItemFontSize}" />
                                </Style>
                            </Grid.Resources>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="SelectionStates">
                                    <VisualStateGroup.Transitions>
                                        <VisualTransition From="Unselected" GeneratedDuration="0:0:0.33" To="UnselectedLocked" />
                                        <VisualTransition From="UnselectedLocked" GeneratedDuration="0:0:0.33" To="Unselected" />
                                    </VisualStateGroup.Transitions>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseMediumLowBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Unselected" />
                                    <VisualState x:Name="UnselectedLocked">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0"
                                                             Storyboard.TargetName="ContentPresenterTranslateTransform"
                                                             Storyboard.TargetProperty="X"
                                                             To="{ThemeResource PivotHeaderItemLockedTranslation}" />
                                            <DoubleAnimation Duration="0"
                                                             Storyboard.TargetName="ContentPresenter"
                                                             Storyboard.TargetProperty="(UIElement.Opacity)"
                                                             To="0" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Selected">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="White" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Red" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="BorderBrush">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Red" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="UnselectedPointerOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseMediumHighBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid" Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="SelectedPointerOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseMediumHighBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid" Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="UnselectedPressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseMediumHighBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid" Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="SelectedPressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseMediumHighBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid" Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="Border"
                                    BorderBrush="Gray"
                                    BorderThickness="2"
                                    CornerRadius="20">
                                <ContentPresenter x:Name="ContentPresenter"
                                                  Margin="{TemplateBinding Padding}"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                  Content="{TemplateBinding Content}"
                                                  ContentTemplate="{TemplateBinding ContentTemplate}"
                                                  FontFamily="{TemplateBinding FontFamily}"
                                                  FontSize="{TemplateBinding FontSize}"
                                                  FontWeight="{TemplateBinding FontWeight}">
                                    <ContentPresenter.RenderTransform>
                                        <TranslateTransform x:Name="ContentPresenterTranslateTransform" />
                                    </ContentPresenter.RenderTransform>
                                </ContentPresenter>
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Page.Resources>
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Pivot x:Name="rootPivot" Title="PIVOT TITLE">
            <PivotItem Header="Pivot Item 1">
                <!--  Pivot content goes here  -->
                <TextBlock Text="Content of pivot item 1." />
            </PivotItem>
            <PivotItem Header="Pivot Item 2">
                <!--  Pivot content goes here  -->
                <TextBlock Text="Content of pivot item 2." />
            </PivotItem>
            <PivotItem Header="Pivot Item 3">
                <!--  Pivot content goes here  -->
                <TextBlock Text="Content of pivot item 3." />
            </PivotItem>
        </Pivot>
    </Grid>
</Page>

And it looks like:
enter image description here

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

枢轴标题样式 的相关文章

  • 添加对共享类的多个 WCF 服务的服务引用

    我正在尝试将我的 WCF Web 服务拆分为几个服务 而不是一个巨大的服务 但是 Visual Studio Silverlight 客户端 复制了两个服务共享的公共类 这是一个简单的例子来说明我的问题 在此示例中 有两个服务 两者都返回类
  • 在 C++ 中分割大文件

    我正在尝试编写一个程序 该程序接受一个大文件 任何类型 并将其分成许多较小的 块 我想我已经有了基本的想法 但由于某种原因我无法创建超过 12 kb 的块大小 我知道谷歌等上有一些解决方案 但我更感兴趣的是了解这个限制的根源是什么 然后实际
  • 在 C++11 中省略返回类型

    我最近发现自己在 C 11 模式下的 gcc 4 5 中使用了以下宏 define RETURN x gt decltype x return x 并编写这样的函数 template
  • std::map 和二叉搜索树

    我读过 std map 是使用二叉搜索树数据结构实现的 BST 是一种顺序数据结构 类似于数组中的元素 它将元素存储在 BST 节点中并按其顺序维护元素 例如如果元素小于节点 则将其存储在节点的左侧 如果元素大于节点 则将其存储在节点的右侧
  • 调试内存不足异常

    在修复我制作的小型 ASP NET C Web 应用程序的错误时 我遇到了 OutOfMemoryException 没有关于在哪里查看的提示 因为这是一个编译时错误 如何诊断此异常 我假设这正是内存分析发挥作用的地方 有小费吗 Thank
  • 如何在 VS 中键入时显示方法的完整文档?

    标题非常具有描述性 是否有任何扩展可以让我看到我正在输入的方法的完整文档 我想查看文档 因为我可以在对象浏览器中看到它 其中包含参数的描述和所有内容 而不仅仅是一些 摘要 当然可以选择查看所有覆盖 它可能是智能感知的一部分 或者我不知道它并
  • C++11 函数局部静态 const 对象的线程安全初始化

    这个问题已在 C 98 上下文中提出 并在该上下文中得到回答 但没有明确说明有关 C 11 的内容 const some type create const thingy lock my lock some mutex static con
  • XAML 中的 CSS 等效项

    在 Web 开发中 样式表非常常用 Swing 中有用于处理 GUI 的布局管理器 我关于 XAML 应用这些范例之一的假设是否正确 两个都 在这种情况下 哪一个是首选 我已经检查过 Intellisense 但除了Style领域 我没有发
  • 单元测试失败,异常代码为 c0000005

    我正在尝试使用本机单元测试项目在 Visual Studios 2012 中创建单元测试 这是我的测试 TEST METHOD CalculationsRoundTests int result Calculations Round 1 0
  • 范围和临时初始化列表

    我试图将我认为是纯右值的内容传递到范围适配器闭包对象中 除非我将名称绑定到初始值设定项列表并使其成为左值 否则它不会编译 这里发生了什么 include
  • 两组点之间的最佳匹配

    I ve got two lists of points let s call them L1 P1 x1 y1 Pn xn yn and L2 P 1 x 1 y 1 P n x n y n 我的任务是找到它们点之间的最佳匹配 以最小化它
  • 用于从字符串安全转换的辅助函数

    回到 VB6 我编写了一些函数 让我在编码时无需关心字符串的 null 和 数字的 null 和 0 等之间的区别 编码时 没有什么比添加特殊情况更能降低我的工作效率了用于处理可能导致一些不相关错误的数据的代码 9999 10000 如果我
  • “MyClass”的类型初始值设定项引发异常

    以下是我的Windows服务代码 当我调试代码时 我收到错误 异常 CSMessageUtility CSDetails 的类型初始值设定项引发异常 using System using System Collections Generic
  • std::bind 重载解析

    下面的代码工作正常 include
  • Qt - 设置不可编辑的QComboBox的显示文本

    我想将 QComboBox 的文本设置为某些自定义文本 不在 QComboBox 的列表中 而不将此文本添加为 QComboBox 的项目 此行为可以在可编辑的 QComboBox 上实现QComboBox setEditText cons
  • Silverlight Datagrid:在对列进行排序时突出显示整个列

    我的 Silverlight 应用程序中有一个 DataGrid 我想在对该列进行排序时突出显示整个列 它在概念上与上一个问题类似 Silverlight DataGrid 突出显示整列 https stackoverflow com qu
  • gdb查找行号的内存地址

    假设我已将 gdb 附加到一个进程 并且在其内存布局中有一个文件和行号 我想要其内存地址 如何获取文件x中第n行的内存地址 这是在 Linux x86 上 gdb info line test c 56 Line 56 of test c
  • 我应该在应用程序退出之前运行 Dispose 吗?

    我应该在应用程序退出之前运行 Dispose 吗 例如 我创建了许多对象 其中一些对象具有事件订阅 var myObject new MyClass myObject OnEvent OnEventHandle 例如 在我的工作中 我应该使
  • 为什么 Ajax.BeginForm 在 Chrome 中不起作用?

    我正在使用 c NET MVC2 并尝试创建一个 ajax 表单来调用删除数据库记录 RemoveRelation 的方法 删除记录的过程正在按预期进行 删除记录后 表单应调用一个 JavaScript 函数 从视觉效果中删除该记录 Rem
  • 以编程方式使用自定义元素创建网格

    我正在尝试以编程方式创建一个网格 并将自定义控件作为子项附加到网格中 作为 2x2 矩阵中的第 0 行第 0 列 为了让事情变得更棘手 我使用了 MVVM 设计模式 下面是一些代码可以帮助大家理解这个想法 应用程序 xaml cs base

随机推荐

  • Team Foundation Server 和 Team Services 之间的区别

    Microsoft Team Foundation Server 和 Microsoft Team Services 之间有什么区别 Team Services 是否也用于持续集成 它可以与自托管 git 服务一起使用吗 希望这不是偏离主题
  • 单独线程中的无限循环

    我有一些数据库优化例程需要定期执行 我目前正在使用 TTimer 但主 VCL 冻结并且非常 hacky 我想知道最好的方法是什么 以降低 cpu 消耗并执行这些例程 我认为将例程放在具有低线程优先级的单独线程中是最好的方法 有任何想法吗
  • Rabbitmq消息到达时间戳

    有没有办法从消费者那里获取消息放入队列时的时间戳 不是当它发布的时候 而是当它真正进入队列的时候 不 没有办法解决这个问题 除非 正如您自己所说 您为此编写了一个插件 AMQP 中没有任何内容规格 http www amqp org sit
  • Android 应用程序干净的架构:数据层应该有自己的模型类吗?

    开发 Android 应用程序并尝试遵循干净的架构准则时 最好的方法是什么 但不是非常严格 因为这对于较小的项目可能有点过分 就我而言 我不确定哪种方法是最好的 如果有最好的方法 关于 数据层数据层是否应该在其自己的模型类上操作 或者是否可
  • 对 foreach 中的数组中的项目进行分组和求和

    我正在循环访问两个存储过程的结果集 根据另一个存储过程中的字段获取一个存储过程中的结果 包含结果集的两个数组是 customers and subcustomers foreach customers as customer foreach
  • 如何在MVC3中的Html beginform中发送javascript var

    我正在尝试使用 html beginform 将 JS 变量发送到控制器操作 例如 using Html BeginForm Index Contrl1 new SPName myJSVarcomeshere FormMethod Post
  • 即使与 libole32 链接,外部库中也未定义 OLE 引用

    使用 MINGW 我尝试将我的 C 代码与执行一些 OLE 操作的静态 C 库链接 mingw32 gcc main o resources o o mbcom exe L Lib Iup liup liupole lole32 lcomc
  • ggplot2:从包含geom_histogram的绘图对象读取最大条形高度

    像这样上一张海报 https stackoverflow com questions 7611691 relative positioning of geom text in ggplot2 我也在用geom text在 gglot2 中注
  • 远程 emacs 客户端连接,但不在终端中创建新框架

    我以 TCP 模式配置并启动了 emacs 服务器 Added setq server host 10 16 184 33 and setq server use tcp t 到 emacs ran emacs daemon 在同一主机上
  • 在 Django 模板中调用 Python 函数

    在 django 模板内 我尝试对其中一个模板变量调用 split 函数 然后获取最后一个元素 所以我做了如下操作 newsletter NewsletterPath split 1 不幸的是 它不喜欢分裂 有些人可能建议我在视图中进行拆分
  • 使用 NiFi 更新 CSV 内字段中的值

    我想实现一个简单的用例 使用 NiFi 将 CSV 内字段中的多个字符串 文本值更新为整数值 例如 我的 CSV 文件如下所示 输入 CSV 文件 字段 1 字段 2 美国 苹果 美国 苹果 印度 葡萄 中国城 奥兰治 澳大利亚民族 桃子
  • 如何让 QLabel 扩展到全宽?

    我想要一个QLabel无论内容如何 都扩展到容器的整个宽度 我想要这个 因为我动态设置文本并稍后添加小部件 这导致它切断部分文本 Widget Widget QWidget parent QWidget parent this gt set
  • 使用宏对数据集中的列按组求和

    我有一个数据集 如下所示 Month Cost Center Account Actual Annual Budget June 53410 Postage 13 234 June 53420 Postage 0 432 June 5343
  • javascript中div的随机位置

    我正在尝试使用 javascript 使 Div 随机出现在网页上的任何位置 因此 一个 div 出现然后消失 然后另一个 div 出现在页面上的其他位置然后消失 然后另一个 div 再次出现在页面上的另一个随机位置然后消失 依此类推 我不
  • 使用 csv 文件进行 Flyway 特定迁移

    我们正在使用 Flyway 通过 sql 脚本在我们的测试环境中保持最新的许多数据库 并且它工作得很好 但我们还特别需要使用 csv 文件更新数据库 我知道 Flyway 提供了一些基于 Java 的迁移来处理更复杂的更新 但问题是这些 J
  • 如何读取基于EMV的智能VISA卡详细信息

    我正在尝试从 VISA 卡读取信用卡数据 但无法成功 正如在互联网资源中我发现对于 MASTER 卡 我们可以使用 1PAY SYS DDF01 文件选择 PSE 目录 然后阅读记录 但对于 VISA 来说 它不是强制性的 当我使用 SEL
  • WeakReference 的 Java 文档中的矛盾

    这个问题是关于理解Java文档中WeakReference的问题 当我读到Java的WeakReference时 我在文档中看到了这样一句话 假设垃圾收集器在某个时刻确定 对象弱可达的时间 到时候就会 原子地清除对该对象的所有弱引用以及所有
  • Objective C 使用字符串动态调用方法

    我只是想知道是否有一种方法可以调用一个方法 我可以用字符串动态构建方法的名称 例如我有一个名为 loaddata 的方法 void loadData 我通常会这样称呼它 self loadData 但我希望能够使用字符串动态调用它 例如 N
  • AngularJS:为什么 ng-bind 在角度上比 {{}} 更好?

    我参加了一场有角度的演讲 其中提到了会议中的一位人士ng bind比 捆绑 原因之一 ng bind将变量放入监视列表中 只有当模型发生更改时 数据才会推送到视图 另一方面 每次都会对表达式进行插值 我猜是角度周期 并推送该值 无论该值是否
  • 枢轴标题样式

    C UWP Windows 10 项目 I need to set Pivot header style to something like this 我尝试使用这个例子堆栈溢出 https stackoverflow com questi