简体   繁体   中英

WP7 Custom Pivot control flickering

Since there is no Border.Effect property in Silverlight for Windows Phone, I managed to recreate a similar effect. What came up after editing the stile of a Pivot control is this:

在此处输入图片说明

As you can see the project is one of Visual Studio default templates. With my custom style, the ItemsPanel is behind that black/gray gradient so, when you scroll the list, it's like items are disappearing.

<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>

The problem is that whenever I slide towards PivotItems the two Grid with a gradient background flicker. What could be the problem?

UPDATE: The flickering only appears when I navigate back to this page

Solved setting CacheMode to the Grid elements. For Example:

<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>

与其重新设置数据透视表的样式以添加背景,您可能会发现创建单个图像用作页面背景并使数据透视表背景保持透明要容易得多。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM