xaml – 如何设置PivotItem标头样式
发布时间:2020-12-13 23:37:59 所属栏目:Windows 来源:网络整理
导读:我有一个我正在使用的现有Pivot标题模板,但它没有给我我需要的效果.我需要当前选择的PivotItem具有蓝色前景和白色背景,而所有其他枢轴项目具有标准禁用前景和背景外观.目前下面我有我认为除了选定的PivotItem上的蓝色前景之外的一切,但我无法弄清楚如何正确
我有一个我正在使用的现有Pivot标题模板,但它没有给我我需要的效果.我需要当前选择的PivotItem具有蓝色前景和白色背景,而所有其他枢轴项目具有标准禁用前景和背景外观.目前下面我有我认为除了选定的PivotItem上的蓝色前景之外的一切,但我无法弄清楚如何正确地将前景应用于所选项目?
<Style x:Key="PivotHeaderItemStyle1" TargetType="Primitives:PivotHeaderItem"> <Setter Property="Background" Value="Transparent"/> <Setter Property="Padding" Value="21,1,0"/> <Setter Property="Margin" Value="0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Primitives:PivotHeaderItem"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="SelectionStates"> <VisualState x:Name="Unselected"> <Storyboard> <ColorAnimation Duration="0" Storyboard.TargetName="myback" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="{StaticResource PhoneDisabledColor}"/> </Storyboard> </VisualState> <VisualState x:Name="Selected"> <Storyboard> <ColorAnimation Duration="0" Storyboard.TargetName="myback" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="{StaticResource PhoneBackgroundColor}"/> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border x:Name="myback" Background="{TemplateBinding Background}"> <ContentControl x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Opacity="{StaticResource PhonePivotUnselectedItemOpacity}"/> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <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}" Grid.RowSpan="3"/> <ContentControl x:Name="TitleElement" ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" HorizontalAlignment="Left" Margin="24,-7" Style="{StaticResource PivotTitleStyle}"/> <Primitives:PivotHeadersControl x:Name="HeadersListElement" Grid.Row="1" ItemContainerStyle="{StaticResource PivotHeaderItemStyle1}" FontSize="70"/> <ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}" Grid.Row="2"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
更改< ContentPresenter>到< TextBlock>
像这样 <Style x:Key="PivotHeaderItemStyle1" TargetType="Primitives:PivotHeaderItem"> <Setter Property="Background" Value="Transparent"/> <Setter Property="Padding" Value="10,10,0"/> <Setter Property="Margin" Value="0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Primitives:PivotHeaderItem"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="SelectionStates"> <VisualState x:Name="Unselected"> <Storyboard> <ColorAnimation Duration="0" Storyboard.TargetName="border_highlight" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="Transparent"/> <ColorAnimation Duration="0" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" To="Green"/> </Storyboard> </VisualState> <VisualState x:Name="Selected"> <Storyboard> <ColorAnimation Duration="0:0:1" Storyboard.TargetName="border_highlight" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="PaleGreen"/> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="contentPresenter"/> <ColorAnimation Duration="0" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" To="Blue"/> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border x:Name="border_highlight" Background="{TemplateBinding Background}" > <!--<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Opacity="{StaticResource PhonePivotUnselectedItemOpacity}"/>--> <TextBlock x:Name="contentPresenter" Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Opacity="{StaticResource PhonePivotUnselectedItemOpacity}"></TextBlock> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> 然后你可以动画前景.这是上面代码的屏幕截图.选择颜色=蓝色,未选择颜色=绿色.您需要在背景动画中添加回来. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows – Heroku:’https://git.heroku.com’的用户名:
- windows 与 Linux 互传文件
- windows-phone-7 – wp7 – 带有大量文本的TextBlock – 巨
- windows – 如何使用schtasks.exe安排一个月中的多天任务?
- windows-server-2008 – schtasks – 创建没有按需运行的计
- windows环境:idea或者eclipse指定用户名操作hadoop集群
- Microsoft Dynamic CRM集成SharePoint
- 如何以编程方式检查当前进程在Windows上是否具有长路径感知
- windows – Perf mon _total vs
- Windows – 混合来自不同版本的Visual Studio的库时的运行时
推荐文章
站长推荐
热点阅读