自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

ToastPrompt在Windows Phone開(kāi)發(fā)中的用法

譯文
移動(dòng)開(kāi)發(fā)
在這篇文章中,我們將會(huì)探討如何在Windows Phone開(kāi)發(fā)中使用ToastPrompt控件。ToastPrompt控件是開(kāi)源類(lèi)庫(kù)Coding4Fun中的一種。同時(shí),在文章中也會(huì)介紹一些ToastPrompt的主要特點(diǎn),提供一些公共的API等。

在這篇文章中,我們將會(huì)探討如何在Windows Phone開(kāi)發(fā)中使用ToastPrompt控件。ToastPrompt控件是開(kāi)源類(lèi)庫(kù)Coding4Fun中的一種。同時(shí),在文章中也會(huì)介紹一些ToastPrompt的主要特點(diǎn),提供一些公共的API等。

步驟1:首先,我們要?jiǎng)?chuàng)建一個(gè)簡(jiǎn)單的Windows Phone應(yīng)用程序,讓我們來(lái)看看如何創(chuàng)建:

◆打開(kāi)Visual Studio 2010

◆文件 - >新建 - >項(xiàng)目

◆選擇Silverlight for Windows Phone模板

◆選擇Windows Phone application

◆給這個(gè)項(xiàng)目起一個(gè)你想要的名字

新建Windows Phone應(yīng)用程序

步驟2:這一步,我們將會(huì)添加Coding4Fun里的引用(reference),具體添加步驟請(qǐng)看下圖。

添加引用 

添加引用 

添加引用

步驟3:在此步驟中,我們將會(huì)在MainPage.xaml.cs文件中添加一個(gè)命名空間(namespace)。

添加一個(gè)命名空間

步驟4:這里,你會(huì)看到MainPage.xaml.cs文件的代碼。

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Net;  
  5. using System.Windows;  
  6. using System.Windows.Controls;  
  7. using System.Windows.Documents;  
  8. using System.Windows.Input;  
  9. using System.Windows.Media;  
  10. using System.Windows.Media.Animation;  
  11. using System.Windows.Shapes;  
  12. using Microsoft.Phone.Controls;  
  13. using Coding4Fun.Phone.Controls;  
  14. using System.Windows.Media.Imaging;  
  15. namespace Myapp  
  16. {  
  17.    public partial class MainPage : PhoneApplicationPage  
  18.    {  
  19.        // Constructor  
  20.        public MainPage()  
  21.        {  
  22.            InitializeComponent();  
  23.        }  
  24.        void MyTP_Completed(object sender, PopUpEventArgs<string, PopUpResult> e)  
  25.        {  
  26.            //add some code here  
  27.        }  
  28.        private void Mybutton1_Click(object sender, RoutedEventArgs e)  
  29.        {  
  30.          ToastPrompt MyTP = new ToastPrompt();  
  31.          MyTP.Title = "MySimpleToastPromt";  
  32.          MyTP.Message = "It's Simply a Toast Prompt";  
  33.          MyTP.FontSize = 40;  
  34.          MyTP.TextOrientation = System.Windows.Controls.Orientation.Vertical;  
  35.          MyTP.ImageSource = new BitmapImage(new Uri("ApplicationIcon.png", UriKind.RelativeOrAbsolute));  
  36.          MyTP.Completed += MyTP_Completed;  
  37.          MyTP.Show();  
  38.        }  
  39.        private void Mybutton2_Click(object sender, RoutedEventArgs e)  
  40.        {  
  41.           var MyTP = new ToastPrompt  
  42.            {  
  43.                Title = "MyPrompt",  
  44.                Message = "Hiiiii THis is a ToastPrompt",  
  45.                ImageSource = new BitmapImage(new Uri("..\\ApplicationIcon.png", UriKind.RelativeOrAbsolute)),  
  46.                Background=new SolidColorBrush(Colors.LightGray)  
  47.            };  
  48.           MyTP.Show();  
  49.        }  
  50.     }  

 

步驟5:這里,你將會(huì)看到MainPage.xaml文件的代碼。

  1. <phone:PhoneApplicationPage 
  2.     x:Class="Myapp.MainPage" 
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  5.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
  6.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
  7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  9.     mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
  10.     FontFamily="{StaticResource PhoneFontFamilyNormal}" 
  11.     FontSize="{StaticResource PhoneFontSizeNormal}" 
  12.     Foreground="{StaticResource PhoneForegroundBrush}" 
  13.     SupportedOrientations="Portrait" Orientation="Portrait" 
  14.     shell:SystemTray.IsVisible="True"> 
  15.     <!--LayoutRoot is the root grid where all page content is placed--> 
  16.     <Grid x:Name="LayoutRoot" Background="Transparent"> 
  17.         <Grid.RowDefinitions> 
  18.             <RowDefinition Height="Auto"/> 
  19.             <RowDefinition Height="*"/> 
  20.         </Grid.RowDefinitions> 
  21.         <!--TitlePanel contains the name of the application and page title--> 
  22.         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> 
  23.             <TextBlock x:Name="PageTitle" Text="My Toast App" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" FontFamily="Comic Sans MS" FontSize="48"> 
  24.                <TextBlock.Foreground> 
  25.                   <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
  26.                     <GradientStop Color="Black" Offset="0" /> 
  27.                     <GradientStop Color="#FFF8C1BE" Offset="1" /> 
  28.                   </LinearGradientBrush> 
  29.                </TextBlock.Foreground> 
  30.             </TextBlock> 
  31.         </StackPanel> 
  32.         <!--ContentPanel - place additional content here--> 
  33.              <StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
  34.                     <Button Content="Click to see Toast Prompt" Click="Mybutton1_Click" FontFamily="Comic Sans MS" FontSize="28" /> 
  35.             <Button Content="Simple usage" Click="Mybutton2_Click" FontFamily="Comic Sans MS" FontSize="26"> 
  36.                 <Button.Background> 
  37.                     <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
  38.                         <GradientStop Color="Black" Offset="0" /> 
  39.                         <GradientStop Color="#FFE4D4E5" Offset="1" /> 
  40.                     </LinearGradientBrush> 
  41.                 </Button.Background> 
  42.             </Button> 
  43.         </StackPanel> 
  44.        </Grid> 
  45. </phone:PhoneApplicationPage> 

 

步驟6:在這一步,你將會(huì)看到MainPage.xaml文件的設(shè)計(jì)頁(yè)面。

MainPage.xaml文件的設(shè)計(jì)界面

步驟7:現(xiàn)在,我們將要運(yùn)行這個(gè)程序(F5),輸出畫(huà)面如下。

輸出1:這是默認(rèn)的輸出畫(huà)面:

輸出畫(huà)面

輸出2:在這個(gè)畫(huà)面中,你會(huì)看到點(diǎn)擊***個(gè)按鈕之后,ToastPrompt的顯示效果。

輸出畫(huà)面

輸出3:在這個(gè)畫(huà)面中,你會(huì)看到點(diǎn)擊第二個(gè)按鈕之后,ToastPrompt的顯示效果。

輸出畫(huà)面

原文鏈接:http://www.c-sharpcorner.com/UploadFile/74f20d/working-with-toastprompt-in-windows-phone-7/

【編輯推薦】

  1. 在WP開(kāi)發(fā)中使用Coding4Fun工具包
  2. 開(kāi)源類(lèi)庫(kù)Coding4Fun中的ToastPrompt控件介紹
責(zé)任編輯:王曉東
相關(guān)推薦

2010-05-11 16:47:32

Windows Pho

2010-06-09 16:13:23

Windows Pho

2010-06-11 16:01:26

Windows Pho

2012-05-25 09:09:25

Windows Pho

2010-04-08 17:40:23

Windows Pho

2010-05-21 16:24:05

Windows Pho

2013-07-30 10:44:31

Windows PhoWindows Pho

2011-06-17 14:16:21

ListBoxWindows Pho

2010-06-21 15:39:59

Windows Pho

2013-07-30 12:37:56

Windows PhoWindows Pho

2010-04-21 17:07:54

Windows Pho

2010-06-11 17:01:09

Windows Pho

2010-05-08 16:36:16

Windows Pho

2011-06-07 12:42:15

Windows Pho

2013-04-17 14:00:06

Windows PhoWindows Pho

2013-04-16 17:02:50

Windows Pho概論

2013-04-19 16:34:56

Windows PhoWindows Pho

2013-07-30 11:18:37

Windows PhoWindows Pho

2010-11-01 14:49:20

Windows PhoWindows Pho

2010-12-21 10:02:48

SilverlightWindows Pho
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)