WP7 Custom Pivot控件闪烁

时间:2013-09-11 07:30:59

标签: silverlight xaml windows-phone-7 styles pivotviewer

由于Silverlight for Windows Phone中没有Border.Effect属性,因此我设法重新创建了类似的效果。在编辑Pivot控件的阶梯之后出现的是:

enter image description here

如您所见,该项目是Visual Studio默认模板之一。 使用我的自定义样式,ItemsPanel位于黑色/灰色渐变的后面,因此,当您滚动列表时,就像项目正在消失。

<Style x:Key="PivotStyle1" TargetType="controls:Pivot">
            <Setter Property="Margin" Value="0"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <ItemsPanelTemplate>
                            <Grid />
                        </ItemsPanelTemplate>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="controls:Pivot">
                        <Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="70" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid Background="{TemplateBinding Background}" CacheMode="BitmapCache" Grid.RowSpan="3"/>

                            <Grid Grid.Row="1">
                                <ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}" VerticalAlignment="Top"/>

                                <Grid Height="50" VerticalAlignment="Top">
                                    <Grid.Background>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#66000000" Offset="0"/>
                                            <GradientStop Offset="1"/>
                                            <GradientStop Color="#19000000" Offset="0.523"/>
                                        </LinearGradientBrush>
                                    </Grid.Background>
                                </Grid>
                            </Grid>



                            <Grid Height="70" Grid.Row="0" VerticalAlignment="Top">
                                <Grid.Background>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FF1665CD" Offset="1"/>
                                        <GradientStop Color="#FF5395EC"/>
                                    </LinearGradientBrush>
                                </Grid.Background>
                                <Primitives:PivotHeadersControl x:Name="HeadersListElement"/>
                            </Grid>

                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

问题是每当我向PivotItems两个网格滑动时,会出现渐变背景闪烁。可能是什么问题?

更新:只有当我导航回此页面时才会出现闪烁

2 个答案:

答案 0 :(得分:1)

解决了CacheMode元素的Grid设置问题。 例如:

<Grid Height="70" CacheMode="BitmapCache" Grid.Row="0" VerticalAlignment="Top">
                                <Grid.Background>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FF1665CD" Offset="1"/>
                                        <GradientStop Color="#FF5395EC"/>
                                    </LinearGradientBrush>
                                </Grid.Background>
                                <Primitives:PivotHeadersControl x:Name="HeadersListElement"/>
                            </Grid>

答案 1 :(得分:0)

而不是重新设置Pivot添加背景,您可能会发现创建单个图像以用作页面背景并使Pivot背景保持透明更容易。