Windows Phone Development Learning Note (1)
---------A custom Bullet box
Customizing a bullet box in WP can be accomplished through the popup class.
The syntax of the popup is:
[Contentpropertyattribute ("Child")]
[Localizabilityattribute (Localizationcategory.none)]
public class popup:frameworkelement, IAddChild;
This is a small use of the popup
Popup codepopup = new popup ();
TextBlock popuptext = new TextBlock ();
Popuptext.text = "Popup Text";
Popuptext.background = Brushes.lightblue;popuptext.foreground = Brushes.blue;
Codepopup.child = Popuptext;
Of course, it's all copied from MSDN, so let's use it for a moment:
Create a new Window phone project, name casually, create a new class for the box, named Mymessagebox; add member variable on it, private popup popup;
Create a new control layout file, named message, for the layout of the frame;
Add the control you want in the message;
What I've added here is:
<usercontrol x:class="Appstudy_1.message"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"XMLNS:MC="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:ignorable="D"FontFamily="{StaticResource Phonefontfamilynormal}"FontSize="{StaticResource Phonefontsizenormal}"Foreground="{StaticResource Phoneforegroundbrush}"D:designheight="480"D:designwidth="480"> <grid x:name="LayoutRoot"Background="{StaticResource Phonechromebrush}"> <textblock text="Li Gui Hair"Fontsize=" -"/> <button content="OK"/> </Grid></UserControl>
View Code
Then we can add the displayed code in the Mymessagebox, and add the method Show () in Mymessagebox to show the Bullet box
First we need to get the popup new out, namely: Popup=new popup ();
Then new a StackPanel object is used to hold the frame interface,
Add a message to StackPanel,
Create a template for StackPanel,
The Popup object's byte point is then set to StackPanel,
Display the Popup
The code is:
Public voidShow () {Popup=NewPopup (); StackPanel Panel=NewStackPanel (); Panel. Children.add (Newappstudy_1.message ()); Panel. Children.add (NewRectangle {Width =480, Height = -, Fill =NewSolidColorBrush (colors.gray), Opacity =0.5 }); Popup. Child=Panel; Popup. IsOpen=true; }
View Code
Add a button in the main window and set the click function to execute the Show method;
This is where you can display the window.