数据透视图项目标题颜色更改所有标题的不透明度在Windows Phone 8.1数据透视控件中保持相同

时间:2014-06-23 10:25:43

标签: windows-phone-8 windows-8.1 windows-phone-8.1

我正在使用Windows Phone 8.1中的数据透视控件我设置前景属性pivotitem标题为红色它工作正常但是,我将所有项目标题设置为红色并且项目标题的不透明度永远不会更改未聚焦的数据透视图云请帮我解决这个问题 问题。 这是代码

   <Pivot Title="Pivot Title" >
        <PivotItem >
            <PivotItem.Header >
                <TextBlock Text="One" Foreground="Red" FontSize="48"/>
            </PivotItem.Header>
        </PivotItem>
        <PivotItem>
            <PivotItem.Header>
                <TextBlock Text="two" Foreground="Red" FontSize="48"/>
            </PivotItem.Header>
        </PivotItem>
        <PivotItem>
            <PivotItem.Header>
                <TextBlock Text="three" Foreground="Red" FontSize="48"/>
            </PivotItem.Header>
        </PivotItem>
    </Pivot>

2 个答案:

答案 0 :(得分:6)

默认样式应该在资源字典<ResourceDictionary.ThemeDictionaries> <ResourceDictionary x:Key="Default"> <SolidColorBrush x:Key="PivotHeaderForegroundUnselectedBrush" Color="#AFAFAF" /> <SolidColorBrush x:Key="PivotHeaderForegroundSelectedBrush" Color="#56C5FF" /> </ResourceDictionary> </ResourceDictionary.ThemeDictionaries>

中覆盖

答案 1 :(得分:-1)

我想你需要为Selected或Unselected状态设置不同的VisualState

请查看How to Change Pivot Header Template in Windows Phone 8

或者您可以使用SelectionChanged事件处理程序作为数据透视表:

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);
        }
    }
}

希望它有所帮助!

相关问题