This program displays a popup box with hello world text
To Display a Popup in windows phone 7, First of all create two PhoneApplicationPage For Example :
1- MainPage.xaml -> Startup Page for the Application in which popup will be shown
2- PopupView.xaml -> Popup page that contains all the stuff to be displayed in the popup.
(All the code for .xaml extension should be placed inside phoneapplicationsettings tag or usercontrol tag)
————————*——————————————————
Code for Popupview.xaml
———————-*——————————————————
Code for MainPage.xaml.cs using System.Windows; using Microsoft.Phone.Controls; using System.Windows.Controls.Primitives; namespace HowtoUsePopup { public partial class MainPage : PhoneApplicationPage { /// /// Constructor /// public MainPage() { InitializeComponent(); } /// /// Click event to show Hello World Popup /// /// object /// RoutedEventArgs private void btnShowPopUp_Click(object sender, RoutedEventArgs e) { Popup PopupView; PopupView = new Popup(); //set the content to be hosted inside the popup. PopupView.Child = new PopupView(); PopupView.IsOpen = true; PopupView.VerticalOffset = 100;// distance of the popup from the top PopupView.HorizontalOffset = 40;// distance of the popup from the left } } }
———————-*——————————————————
Code for popupView.xaml.cs using System.Windows; using Microsoft.Phone.Controls; using System.Windows.Controls.Primitives; namespace HowtoUsePopup { public partial class PopupView : PhoneApplicationPage { /// /// constructor /// public PopupView() { InitializeComponent(); } /// /// function to closethe popup box /// private void ClosePopup() { Popup popupHelloWorld= this.Parent as Popup; popupHelloWorld .IsOpen = false; } /// /// Event to close popup /// /// object /// RoutedEventArgs private void btnClose_Click(object sender, RoutedEventArgs e) { ClosePopup(); } } }
———————–END—————————————————–