One of the biggest problem with Windows Phone is that you do not have ChildWindow and hopefully this will change in next release. But for now you will need to you the Popup found in System.Windows.Controls.Primitives. You will learn how to use the Popup and be able to customize. As part of the demo you will be creating BuyNow Popup screen.
Create UI BuyNowScreen.xaml
Add Windows Phone user control and design the control way you want it to look. For this demo you will see following BuyNowScreen design.
Code BuyNowScreen
Notice here that when you create BuyNowScreen user control and you have constructor where you need to pass the message which gets set to txtMessage.Text. When BuyNow button is clicked you will be opening the Marketplace detail page of you current application. This is done by setting ContentIdentifier (ProductId) to be null.
private void btnBuy_Click(object sender, RoutedEventArgs e)
{
ClosePopup();
MarketplaceDetailTask detailTask = new MarketplaceDetailTask();
detailTask.Show();
}
Notice neat trick of closing the current Popup is to access the Parent of the BuyNowScreen user control which is Popup and set IsOpen to false.
private void ClosePopup()
{
Popup buyPop = this.Parent as Popup;
buyPop.IsOpen = false;
}
Invoke BuyNowScreen.xaml as Popup
Trick here is to assign your own user control that you design to Child property of the Popup as show in below code. Then you set the vertical and horizontal off set which will control where the Popup will be displayed. When you set the IsOpen to true the Popup will be displayed. There is event which you can subscribe to do any extra work upon Popup Closed.
private void btnShowBuyNow_Click(object sender, RoutedEventArgs e)
{
Popup buyNowScreen;
buyNowScreen = new Popup();
buyNowScreen.Child =
new BuyNowScreen
(“Buy this application and get rid of the ads!”);
buyNowScreen.IsOpen = true;
buyNowScreen.VerticalOffset = 100;
buyNowScreen.HorizontalOffset = 25;
buyNowScreen.Closed += (s1, e1) =>
{
// Add you code here to do something
// when the Popup is closed
};
}
Conclusion
So in this demo you learned how to customize the Popup and programmatically open and close the Popup and handle Popup Closed event.


Pingback: Windows Phone 中的弹出窗口 » NoName
Usefull
thank you
Pingback: The popup Windows please
Great ! thank you !