我得到了解决!
要创建自定义透视标题,您需要创建一个XAML用户控件。下面是我叫TabHeader.xaml我的用户控件:
<UserControl
x:Class="Edelweisuniversalapp.Pages.Dashboard.TabHeader"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Edelweisuniversalapp.Pages.Dashboard"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="128"
d:DesignWidth="128">
<Grid Height="128" Width="128">
<StackPanel>
<FontIcon
HorizontalAlignment="Center"
Margin="0,12,0,0"
Glyph="{Binding Glyph}"
FontSize="16"
/>
<TextBlock
FontFamily="Segoe UI"
Text="{Binding Label}"
Style="{StaticResource CaptionTextBlockStyle}"
LineStackingStrategy="BlockLineHeight"
LineHeight="14"
MaxLines="2"
IsTextScaleFactorEnabled="False"
TextAlignment="Center"
HorizontalAlignment="Center"
Margin="2,5,2,7"
/>
</StackPanel>
</Grid>
并且在下面的TabHeader.xaml.cs:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace Edelweisuniversalapp.Pages.Dashboard
{
public sealed partial class TabHeader : UserControl
{
public string Glyph
{
get { return (string)GetValue(GlyphProperty); }
set { SetValue(GlyphProperty, value); }
}
// Using a DependencyProperty as the backing store for Glyph. This enables animation, styling, binding, etc...
public static readonly DependencyProperty GlyphProperty =
DependencyProperty.Register("Glyph", typeof(string), typeof(TabHeader), null);
public string Label
{
get { return (string)GetValue(LabelProperty); }
set { SetValue(LabelProperty, value); }
}
// Using a DependencyProperty as the backing store for Label. This enables animation, styling, binding, etc...
public static readonly DependencyProperty LabelProperty =
DependencyProperty.Register("Label", typeof(string), typeof(TabHeader), null);
public TabHeader()
{
this.InitializeComponent();
this.DataContext = this;
}
}
}
然后你可以使用在用户控制这样的转动控制:
<Pivot Style="{StaticResource TabsStylePivotStyle}" Grid.Row="0">
<PivotItem>
<PivotItem.Header>
<local:TabHeader Height="124" Label="Inbox" Glyph=""/>
</PivotItem.Header>
<PivotItem.Content>
<TextBlock Text="Content content content1"/>
</PivotItem.Content>
</PivotItem>
<PivotItem>
<PivotItem.Header>
<local:TabHeader Height="124" Label="Draft" Glyph=""/>
</PivotItem.Header>
<PivotItem.Content>
<TextBlock Text="Content content content2"/>
</PivotItem.Content>
</PivotItem>
<PivotItem>
<PivotItem.Header>
<local:TabHeader Height="124" Label="Outbox" Glyph=""/>
</PivotItem.Header>
<PivotItem.Content>
<TextBlock Text="Content content content3"/>
</PivotItem.Content>
</PivotItem>
</Pivot>
这里是结果http://i.stack.imgur.com/gUF46.jpg
你能告诉你如何设置中心标题? –
如果有人想知道,可以使用Windows上的Character Map程序查看可用的字形代码。 Windows 10中的字体是“Segoe MDL2 Assets”。 – Josh
@JakubWisniewski,答案就在这里:https://blog.hompus.nl/2015/09/04/responsive-pivot-headers-in-universal-windows-platform-apps/ Set'HeaderClipper.HorizontalContentAlignment ',给它一个值='“中心”'。 – Josh