首先,我们先建立一个空白的Windowsphone8.1应用程序,在对应的MainPage.xaml文件中将代码改成下述样式:
<Page x:Class="XAMLControls.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:XAMLControls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid> <TextBlock x:Name="myTextBlock" HorizontalAlignment="Left" Margin="32,78,0,0" TextWrapping="Wrap" Text="" FontSize="24" VerticalAlignment="Top"/> <Button x:Name="myButton" Content="Button" HorizontalAlignment="Left" Margin="23,127,0,0" VerticalAlignment="Top" Click="myButton_Click"/> <TextBox x:Name="myTextBox" HorizontalAlignment="Left" Margin="32,197,0,0" TextWrapping="NoWrap" Text="" InputScope="TelephoneNumber" VerticalAlignment="Top" Width="120"/> <!-- InputScope:当用户在该控件中输入数据时会弹出不同类型的键盘--> <ComboBox x:Name="myComBox" HorizontalAlignment="Left" Margin="32,260,0,0" VerticalAlignment="Top" Width="120"> <ComboBoxItem Content="First Item" IsSelected="True"/> <ComboBoxItem Content="Second Item"/> <ComboBoxItem Content="Third Item"/> <ComboBoxItem Content="Fourth Item"/> <ComboBoxItem Content="Fifth Item"/> <ComboBoxItem Content="Sixth Item"/> </ComboBox> <CheckBox x:Name="myCheckBox" Content="CheckBox" HorizontalAlignment="Left" Margin="194,120,0,0" VerticalAlignment="Top"/> <RadioButton x:Name="MyFirstRadioButton" Content="RadioButton1" HorizontalAlignment="Left" Margin="194,198,0,0" VerticalAlignment="Top" GroupName="FirstGroup"/> <RadioButton x:Name="MySecondRadioButton" Content="RadioButton2" HorizontalAlignment="Left" Margin="194,239,0,0" VerticalAlignment="Top" GroupName="FirstGroup"/> <RadioButton x:Name="MyThirdRadioButton" Content="RadioButton3" HorizontalAlignment="Left" Margin="194,280,0,0" VerticalAlignment="Top" GroupName="SecondGroup"/> <RadioButton x:Name="MyFourRadioButton" Content="RadioButton4" HorizontalAlignment="Left" Margin="194,320,0,0" VerticalAlignment="Top" GroupName="SecondGroup"/> <DatePicker x:Name="myDatePicker" HorizontalAlignment="Left" Margin="32,349,0,0" VerticalAlignment="Top" DateChanged="myDatePicker_DateChanged"/> <TimePicker x:Name="myTimePicker" HorizontalAlignment="Left" VerticalAlignment="Top"/> <Image x:Name="myImage" HorizontalAlignment="Left" Height="100" Margin="32,429,0,0" VerticalAlignment="Top" Width="100" Source="assets/qtcreator.png"/> <Slider x:Name="mySlider" HorizontalAlignment="Left" Margin="194,424,0,0" VerticalAlignment="Top" Width="168" Maximum="100"/> <ProgressBar x:Name="myProgressBar" HorizontalAlignment="Left" Height="10" Margin="195,483,0,0" VerticalAlignment="Top" Width="100" Maximum="100" Value="{Binding ElementName=mySlider,Path=Value,Mode=OneWay}"/> <ProgressRing x:Name="myProgressRing" HorizontalAlignment="Left" Margin="32,562,0,0" VerticalAlignment="Top" Height="76" Width="76"/> <ToggleButton x:Name="myToggleButton" Content="ToggleButton" HorizontalAlignment="Left" Margin="181,573,0,0" VerticalAlignment="Top" Click="myToggleButton_Click"/> </Grid> </Page>
将上述代码添加后你会发现你的如下图所示:
将对于的MainPage.xaml.cs文件中代码改成下述样式:
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; // “空白页”项模板在 http://go.microsoft.com/fwlink/?LinkId=391641 上有介绍 namespace XAMLControls { /// <summary> /// 可用于自身或导航至 Frame 内部的空白页。 /// </summary> public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; } /// <summary> /// 在此页将要在 Frame 中显示时进行调用。 /// </summary> /// <param name="e">描述如何访问此页的事件数据。 /// 此参数通常用于配置页。</param> protected override void OnNavigatedTo(NavigationEventArgs e) { // TODO: 准备此处显示的页面。 // TODO: 如果您的应用程序包含多个页面,请确保 // 通过注册以下事件来处理硬件“后退”按钮: // Windows.Phone.UI.Input.HardwareButtons.BackPressed 事件。 // 如果使用由某些模板提供的 NavigationHelper, // 则系统会为您处理该事件。 } private void myButton_Click(object sender, RoutedEventArgs e) { // myTextBlock.Text = myTextBox.Text; // myTextBlock.Text = ((ComboBoxItem)myComBox.SelectedItem).Content.ToString(); myTextBlock.Text = (bool)myCheckBox.IsChecked ? "Is Checked" : "Not Checked"; if (MyFirstRadioButton.IsChecked == true) { myTextBlock.Text = " First Radio!"; } else if (MySecondRadioButton.IsChecked == true) { myTextBlock.Text = "Second Radio!"; } else { myTextBlock.Text = "Unknown!"; } } private void myDatePicker_DateChanged(object sender, DatePickerValueChangedEventArgs e) { myTextBlock.Text = myDatePicker.Date.ToString(); } private void myToggleButton_Click(object sender, RoutedEventArgs e) { if (myToggleButton.IsChecked == true) myProgressRing.IsActive = true; else myProgressRing.IsActive = false; } } }
好了,写到这里,你再运行的你程序,你会发下有一些变化的!