Windows 8實用竅門系列:11.Windows 8 中的Toast Tile Badge通知

來源:互聯網
上載者:User

  在Windows 8中有三種通知的方式及時提醒使用者,它們分別是Toast,Tile,Badge

  Toast:是在應用程式中及時彈出的提醒通知。

  Tile:是磁貼通知,用於Metro介面中的應用程式圖示上進行圖片和文字通知。

  Badge:是在磁貼小貼士通知,用於Metro介面中的應用程式圖示右下角提示當前有多少新訊息或者當前應用程式狀態,如(playing paused newMessage)等。

  準備工作:   首先:引用NotificationsExtensions.winmd庫,這是對各種通知簡化訪問的封裝。

        其次:開啟Package.appxmanifest重新設定各種徽標。

        最後:開啟Package.appxmanifest,設定“支援Toast通知”為“是”。

Toast:

        private void ToastNotice_Click(object sender, RoutedEventArgs e)        {            //Toast通知文字以及圖片設定            IToastImageAndText01 Toast = ToastContentFactory.CreateToastImageAndText01();            Toast.TextBodyWrap.Text = "今日世界末日倒數10天!";            Toast.Image.Src = "http://news.shangdu.com/301/20120512/P_5626361_0__1686841290.jpg";            ToastNotificationManager.CreateToastNotifier().Show(Toast.CreateNotification());        }

片:

Tile:

        private void TileNotice_Click(object sender, RoutedEventArgs e)        {            //Tile通知文字以及圖片設定            ITileWideImageAndText01 tile = TileContentFactory.CreateTileWideImageAndText01();            tile.TextCaptionWrap.Text = "小資情有獨鐘 10款合資熱銷時尚車型導購";            tile.Image.Src = "http://news.mycar168.com/uploadfile/2011/1030/20111030040816628.jpg";            ITileSquareImage wideImageContent = TileContentFactory.CreateTileSquareImage();            wideImageContent.Image.Src = "http://news.mycar168.com/uploadfile/2011/1030/20111030040816628.jpg";            tile.SquareContent = wideImageContent;            TileUpdateManager.CreateTileUpdaterForApplication().Update(tile.CreateNotification());        }        private void ClearTile_Click(object sender, RoutedEventArgs e)        {            //清除Tile通知            TileUpdateManager.CreateTileUpdaterForApplication().Clear();        }

片:

Badge:

       private void BadgeNotice_Click(object sender, RoutedEventArgs e)        {            //Badge數字通知            BadgeNumericNotificationContent badge = new BadgeNumericNotificationContent(29);            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge.CreateNotification());        }        private void BadgeImage_Click(object sender, RoutedEventArgs e)        {            //Badge狀態圖片通知            BadgeGlyphNotificationContent badge = new BadgeGlyphNotificationContent(GlyphValue.Paused);            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badge.CreateNotification());        }        private void BadgeClear_Click(object sender, RoutedEventArgs e)        {            //清楚Badge通知            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();        }

圖片效果見圖片右下角:

 

Xaml:

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">        <Button Content="Toast通知" HorizontalAlignment="Left" Name="ToastNotice"                Margin="250,172,0,0" VerticalAlignment="Top" Click="ToastNotice_Click"/>        <Button Content="Tile 通知" HorizontalAlignment="Left" Name="TileNotice"                Margin="394,172,0,0" VerticalAlignment="Top" Click="TileNotice_Click"/>        <Button Content="清除Tile通知" HorizontalAlignment="Left" Name="ClearTile"                Margin="559,172,0,0" VerticalAlignment="Top" Click="ClearTile_Click" />        <Button Content="Badge數字" HorizontalAlignment="Left" Name="BadgeNotice"                Margin="250,270,0,0" VerticalAlignment="Top" Click="BadgeNotice_Click"/>        <Button Content="Badge圖片" HorizontalAlignment="Left" Name="BadgeImage"                Margin="394,270,0,0" VerticalAlignment="Top" Click="BadgeImage_Click" />        <Button Content="Badge清除" HorizontalAlignment="Left" x:Name="BadgeClear"                Margin="559,270,0,0" VerticalAlignment="Top" Click="BadgeClear_Click" />    </Grid>

  最後如需源碼請點擊 Win8Notice.rar 下載。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.