Windows Phone 7开发之启动页面(SplashScreen)

建立一个页面 SplashScreen.xaml

<phone:PhoneApplicationPage 
    x:Class="WebService_CheckWeather.SplashScreen"
    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:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="480"
    shell:SystemTray.IsVisible="False">

    <!--LayoutRoot 是包含所有页面内容的根网格-->
    <Image Height="800" Name="image1" Stretch="Fill" Width="480" Source="/SplashScreenImage.jpg" />       

</phone:PhoneApplicationPage>

MainPage.cs

//全局变量
BackgroundWorker backgroundWorker;
Popup popup;

public MainPage()
        {
            InitializeComponent();

            popup = new Popup()
            {
                IsOpen = true,
                Child = new SplashScreen()
            };

            backgroundWorker = new BackgroundWorker();
            RunBackgroundWorker();

            // 将 listbox 控件的数据上下文设置为示例数据
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

private void RunBackgroundWorker()
        {
            backgroundWorker.DoWork += ((s, args) =>
            {
                Thread.Sleep(2 * 1000);
            });

            backgroundWorker.RunWorkerCompleted += ((s, args) =>
            {
                this.Dispatcher.BeginInvoke(() =>
                {
                    popup.IsOpen = false;
                });
            });
            backgroundWorker.RunWorkerAsync();
        }

 

 

 

posted @ 2012-06-15 19:33  hack25  阅读(391)  评论(0编辑  收藏  举报