How can you prevent the ApplicationBar flickering on the WP7 white theme?

心已入冬 提交于 2020-01-01 08:59:11

问题


I have a Windows Phone 7.1 Mango application where I have mostly successfully overridden the built in theme colors. However, if the user has the white theme selected and the page has a dark background and dark application bar, the application bar gets rendered and animated with a white background which causes an annoying flicker. After it gets done animating the background color gets sets to a dark color appropriately.

Is there a way to either disable the app bar animation or set its initial animation background color?

See this video capture of the flickering issue.

Xaml:

<phone:PhoneApplicationPage x:Class="AppBarFlickers.Page1"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            mc:Ignorable="d"
                            d:DesignWidth="480"
                            d:DesignHeight="728"
                            SupportedOrientations="Portrait"
                            Orientation="Portrait">
    <Grid Background="Black">
        <Button Content="Toggle App Bar"
                Margin="100,185,100,0"
                VerticalAlignment="Top"
                Click="ButtonClick"
                Foreground="White"
                Background="Black"
                BorderBrush="White" />
    </Grid>
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar BackgroundColor="Black"
                              ForegroundColor="White">
            <shell:ApplicationBarIconButton IconUri="/icon.png"
                                            Text="Button 1" />
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>
</phone:PhoneApplicationPage>

Code behind:

public partial class Page1
{
   public Page1()
   {
       InitializeComponent();
   }

   private void ButtonClick(object sender, RoutedEventArgs e)
   {
       ApplicationBar.IsVisible = !ApplicationBar.IsVisible;
   }
}

回答1:


Looks like the background isn't loaded while the ApplicationBar is hiding. It hides the bar, then load the background, hence the flickering.

Found a workaround: set the opacity of the applicationbar to 0.99. It's high enough for the transparency to be invisible, and it will force the application to load the background.

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar BackgroundColor="Black" ForegroundColor="White" Opacity=".99" >
        <shell:ApplicationBarIconButton IconUri="/icon.png" Text="Button 1" />
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>


来源:https://stackoverflow.com/questions/8748552/how-can-you-prevent-the-applicationbar-flickering-on-the-wp7-white-theme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!