Windows 7 development platform
Ready to build WP7 development environment on your computer?
First, install VS2010, upgrade to SP1 , and install the Windows Phone SDK 7.1 RC , you can start writing WP7 program. Here we have to write a simple Hello World program.
Open VS2010, choose File-> New-> Project ... to open the New Project dialog box. Select the Windows Phone Application.
In the screen below, you can choose to develop based on WP 7.0 or 7.1, we take 7.0 for example.
You can see, our system automatically generates two xaml files, and two corresponding cs files. MainPage.xaml in the main interface of the program is, we may need to add content.
In MainPage.xaml, specifies the main interface design. Interface design through a hierarchical structure of XML-like exhibit. All the main interface elements are LayoutRoot under. Now we want to display a text box and a button on the main interface, you can add the following code to ContentPanel:
<Grid X:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </ Grid.RowDefinitions> <TextBlock Text="Name" /> <TextBox X:Name="TxtName" Grid.Row="1" Text="" /> <Button Grid.Row="2"> <TextBlock Text="Submit"/> </ Button> </ Grid>
Effect is shown:
After clicking the relevant buttons , you need to add an event handler in the Button. To define event handlers, there are two ways: one is defined in xaml
directly, other is to add an event response function in the C # code. Here we used the former.
Button's about to change the definition of the statement:
<Button Grid.Row="2" Click="BtnSubmitClick"> <TextBlock Text="Submit"/> </ Button>
And add an event handler in the MainPage.xaml.cs:
private void BtnSubmitClick (object sender, RoutedEventArgs e) { MessageBox.Show ("Hello" + TxtName.Text + ", welcome to the fatanstic WP7 world!"); }
Use Windows Phone Emulator running, you can see the results:
No comments:
Post a Comment