ToastPrompt在Windows Phone开发中的用法

译文
移动开发
在这篇文章中,我们将会探讨如何在Windows Phone开发中使用ToastPrompt控件。ToastPrompt控件是开源类库Coding4Fun中的一种。同时,在文章中也会介绍一些ToastPrompt的主要特点,提供一些公共的API等。

在这篇文章中,我们将会探讨如何在Windows Phone开发中使用ToastPrompt控件。ToastPrompt控件是开源类库Coding4Fun中的一种。同时,在文章中也会介绍一些ToastPrompt的主要特点,提供一些公共的API等。

步骤1:首先,我们要创建一个简单的Windows Phone应用程序,让我们来看看如何创建:

◆打开Visual Studio 2010

◆文件 - >新建 - >项目

◆选择Silverlight for Windows Phone模板

◆选择Windows Phone application

◆给这个项目起一个你想要的名字

新建Windows Phone应用程序

步骤2:这一步,我们将会添加Coding4Fun里的引用(reference),具体添加步骤请看下图。

添加引用 

添加引用 

添加引用

步骤3:在此步骤中,我们将会在MainPage.xaml.cs文件中添加一个命名空间(namespace)。

添加一个命名空间

步骤4:这里,你会看到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:这里,你将会看到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:在这一步,你将会看到MainPage.xaml文件的设计页面。

MainPage.xaml文件的设计界面

步骤7:现在,我们将要运行这个程序(F5),输出画面如下。

输出1:这是默认的输出画面:

输出画面

输出2:在这个画面中,你会看到点击***个按钮之后,ToastPrompt的显示效果。

输出画面

输出3:在这个画面中,你会看到点击第二个按钮之后,ToastPrompt的显示效果。

输出画面

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

【编辑推荐】

  1. 在WP开发中使用Coding4Fun工具包
  2. 开源类库Coding4Fun中的ToastPrompt控件介绍
责任编辑:王晓东
相关推荐

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

2011-06-17 14:16:21

ListBoxWindows Pho

2013-07-30 10:44:31

Windows PhoWindows Pho

2010-05-21 16:24:05

Windows 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-07-30 11:18:37

Windows PhoWindows Pho

2013-04-19 16:34:56

Windows PhoWindows Pho

2013-04-16 17:02:50

Windows Pho概论

2010-12-21 10:02:48

SilverlightWindows Pho

2010-11-01 14:49:20

Windows PhoWindows Pho
点赞
收藏

51CTO技术栈公众号