Windows Phone开发之控件Grid,TextBox,TextBlock,RadioButton,CheckBox,ListBox简介
代码如下:
[html] <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="160*"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="250*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="70"/>
<RowDefinition Height="70"/>
<RowDefinition Height="70"/>
<RowDefinition Height="70"/>
<RowDefinition Height="40"/>
<RowDefinition Height="120"/>
<RowDefinition Height="70"/>
<RowDefinition Height="70"/>
</Grid.RowDefinitions>
<TextBlock Name="textBlock0"
Text="姓名:"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Column="0"
Grid.Row="0"
/>
<TextBlock Name="textBlock1"
Text="工作:"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Column="0"
Grid.Row="1"
/>
<TextBlock Name="textBlock2"
Text="哈哈你懂得:"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Column="0"
Grid.Row="4"
/>
<TextBlock Name="textBlock3"
Text="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Column="0"
Grid.Row="5"
/>
<TextBox Name="textBox_Nam2e"
Text=""
Grid.Column="2"
Grid.Row="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
<CheckBox Name="checkBox1"
Content=""
Grid.Column="2"
Grid.Row="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
<RadioButton Name="radioButton1"
GroupName="myGroup"
Content="FBI"
Grid.Column="2"
Grid.Row="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
<RadioButton Name="radioButton2"
GroupName="myGroup"
Content="CIA"
Grid.Column="2"
Grid.Row="3"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
<ListBox Name="myListBox"
Grid.Column="0"
Grid.Row="5"
Grid.ColumnSpan="3"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" >
<ListBoxItem Name="listBoxItem0"
Content="奥特曼"
/>
<ListBoxItem Name="listBoxItem1"
Content="孙悟空"
/>
<ListBoxItem Name="listBoxItem2"
Content="关羽"
/>
<ListBoxItem Name="listBoxItem3"
Content="周星星"
/>
</ListBox>
<Button Name="button"
Content="Save"
Grid.Column="3"
Grid.Row="6"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
</Grid>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="160*"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="250*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="70"/>
<RowDefinition Height="70"/>
<RowDefinition Height="70"/>
<RowDefinition Height="70"/>
<RowDefinition Height="40"/>
<RowDefinition Height="120"/>
<RowDefinition Height="70"/>
<RowDefinition Height="70"/>
</Grid.RowDefinitions>
<TextBlock Name="textBlock0"
Text="姓名:"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Column="0"
Grid.Row="0"
/>
<TextBlock Name="textBlock1"
Text="工作:"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Column="0"
Grid.Row="1"
/>
<TextBlock Name="textBlock2"
Text="哈哈你懂得:"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Column="0"
Grid.Row="4"
/>
<TextBlock Name="textBlock3"
Text="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Column="0"
Grid.Row="5"
/>
<TextBox Name="textBox_Nam2e"
Text=""
Grid.Column="2"
Grid.Row="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
<CheckBox Name="checkBox1"
Content=""
Grid.Column="2"
Grid.Row="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
<RadioButton Name="radioButton1"
GroupName="myGroup"
Content="FBI"
Grid.Column="2"
Grid.Row="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
<RadioButton Name="radioButton2"
GroupName="myGroup"
Content="CIA"
Grid.Column="2"
Grid.Row="3"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
<ListBox Name="myListBox"
Grid.Column="0"
Grid.Row="5"
Grid.ColumnSpan="3"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" >
<ListBoxItem Name="listBoxItem0"
Content="奥特曼"
/>
<ListBoxItem Name="listBoxItem1"
Content="孙悟空"
/>
<ListBoxItem Name="listBoxItem2"
Content="关羽"
/>
<ListBoxItem Name="listBoxItem3"
Content="周星星"
/>
</ListBox>
<Button Name="button"
Content="Save"
Grid.Column="3"
Grid.Row="6"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
</Grid>
以上控件的后台操作:
[html] if (checkBox1.IsChecked==true) {
MessageBox.Show("this.checkBox1.IsChecked");
}
if (radioButton1.IsChecked == true) {
MessageBox.Show("FBI");
}
foreach (ListBoxItem myList in myListBox.Items) {
if (myList.IsSelected) {
MessageBox.Show(myList.Name+"||"+myList.Content);
}
}
if (checkBox1.IsChecked==true) {
MessageBox.Show("this.checkBox1.IsChecked");
}
if (radioButton1.IsChecked == true) {
MessageBox.Show("FBI");
}
foreach (ListBoxItem myList in myListBox.Items) {
if (myList.IsSelected) {
MessageBox.Show(myList.Name+"||"+myList.Content);
}
}
P.S:两个按钮共用一个点击事件
相似的事件操作可以采用该方法。
[html] private void button_Click(object sender, RoutedEventArgs e){
Button myButton=(Button)sender;
textBlock.Text=myButton.Name;
}
private void button_Click(object sender, RoutedEventArgs e){
Button myButton=(Button)sender;
textBlock.Text=myButton.Name;
}