例如,是否可以将全景控件的标题的前景设为红色,而将另一个标题(我们可以开始看到,因为它是一个枢轴项目)设为灰色?
标题 1 :红色,阴影标题 2 为灰色。
谢谢
例如,是否可以将全景控件的标题的前景设为红色,而将另一个标题(我们可以开始看到,因为它是一个枢轴项目)设为灰色?
标题 1 :红色,阴影标题 2 为灰色。
谢谢
您可以像这样编写 xaml 文件:
    <controls:Pivot Title="My application" Foreground="Red">
        <controls:PivotItem>
            <controls:PivotItem.Header>
                <TextBlock Text="first" Foreground="Gray"></TextBlock>
            </controls:PivotItem.Header>
            <TextBlock Text="content"></TextBlock>
        </controls:PivotItem>
    </controls:Pivot>
您可以使用 SelectionChanged 事件处理程序。如果您将标题定义为 TextBlocks:-
                <controls:Pivot Title="MY APPLICATION"
                    SelectionChanged="Pivot_SelectionChanged">
        <controls:PivotItem>
            <controls:PivotItem.Header>
                <TextBlock Text="first"
                           Foreground="Red" />
            </controls:PivotItem.Header>
        </controls:PivotItem>
        <controls:PivotItem>
            <controls:PivotItem.Header>
                <TextBlock Text="second"
                           Foreground="Red" />
            </controls:PivotItem.Header>
        </controls:PivotItem>
        <controls:PivotItem>
            <controls:PivotItem.Header>
                <TextBlock Text="third"
                           Foreground="Red" />
            </controls:PivotItem.Header>
        </controls:PivotItem>
        <controls:PivotItem>
            <controls:PivotItem.Header>
                <TextBlock Text="fourth"
                           Foreground="Red" />
            </controls:PivotItem.Header>
        </controls:PivotItem>
    </controls:Pivot>
然后,您可以在后面的 C# 代码中更改 TextBlocks 的前景:-
        private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (e.AddedItems.Count > 0)
        {
            PivotItem currentItem = e.AddedItems[0] as PivotItem;
            if (currentItem != null)
            {
                (currentItem.Header as TextBlock).Foreground = new SolidColorBrush(Colors.White);
            }
        }
        if (e.RemovedItems.Count > 0)
        {
            PivotItem currentItem = e.RemovedItems[0] as PivotItem;
            if (currentItem != null)
            {
                (currentItem.Header as TextBlock).Foreground = new SolidColorBrush(Colors.Red);
            }
        }
    }