Windows 10 透视项文本 [英] windows 10 pivot item text

查看:21
本文介绍了Windows 10 透视项文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在选择标题时更改数据透视项标题文本的默认文本样式(前景色、字体粗细等).

I want to change the default text style (foreground color, font weight, etc) for pivot item header text when the header is selected.

例如,如果我有以下内容:

E.g., if I have the following:

<Pivot>
    <PivotItem Header="One"></PivotItem>
    <PivotItem Header="Two"></PivotItem>
</Pivot>

我希望选中的枢轴项在选中和/或更改前景色时加粗(或者可能将文本放在边框等中).我不想更改未选中项的默认样式.

I want the selected pivot item to be bolded when selected and/or change the foreground color (or maybe put the text in a border, etc). I don't want to change the default style for the unselected items.

谢谢,

推荐答案

XAML 框架提供了多种自定义应用外观的方法.样式让您可以设置控件属性并重复使用这些设置,以便在多个控件之间保持一致的外观.当您想要自定义控件的视觉结构和视觉行为时,您可以创建控件模板.

The XAML framework offers many ways to customize the appearance of your apps. Styles let you set control properties and reuse those settings for a consistent appearance across multiple controls. You create a control template when you want to customize a control's visual structure and visual behavior.

您不需要将数据透视标题的文本放在边框中,编辑Style 将是一个不错的选择,您可以将此样式添加到 页面资源.

You don't need to put the text of pivot header in a border, edit the Style for PivotHeaderItem would be a good choice, and you can add this style to the Resources of the Page.

资源通常是您希望多次使用的某个对象的定义.

Resources are typically definitions of some object that you expect to use more than once.

有一个默认的 PivotHeaderItem 样式和模板,您可以复制它并将其添加到您的页面资源中,就像这样:

There is a default PivotHeaderItem styles and templates, you can copy it and add this to you page resources just like this:

<Page
    x:Class="..."
    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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Page.Resources>
        <Style TargetType="PivotHeaderItem">
             ...
        </Style>
    </Page.Resources>
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        ...
    </Grid>
</Page>

现在,如果您想在选择项目时更改标题中文本的前景,您可以像这样编辑 <VisualState x:Name="Selected">:>

Now if you want to change the foreground of the text in header when the item is selected, you can edit the <VisualState x:Name="Selected"> like this:

<VisualState x:Name="Selected">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Red" />
        </ObjectAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid" Storyboard.TargetProperty="Background">
            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" />
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

如果你想把header的文本改成粗体,你可以像这样编辑上面的VisualState:

If you want to change the text of header to be bold, you can edit above VisualState like this:

<VisualState x:Name="Selected">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="FontWeight">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Bold" />
        </ObjectAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid" Storyboard.TargetProperty="Background">
            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" />
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

如果您只想在选择项目时更改样式,您可以将其他 VisualState 保留为默认值.

You can leave other VisualStates as defalut, if you just want to change the style when the item is selected.

这篇关于Windows 10 透视项文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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