The Code is as follows:
The Code is as follows:
<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 = "Name:"
HorizontalAlignment = "Stretch"
VerticalAlignment = "Stretch"
Grid.Column = "0"
Grid.Row = "0"
/>
<TextBlock Name = "textBlock1"
Text = "Work:"
HorizontalAlignment = "Stretch"
VerticalAlignment = "Stretch"
Grid.Column = "0"
Grid.Row = "1"
/>
<TextBlock Name = "textBlock2"
Text = "haha you know:"
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 = "Ultraman"
/>
<ListBoxItem Name = "listBoxItem1"
Content = "Sun Wukong"
/>
<ListBoxItem Name = "listBoxItem2"
Content = "Guan Yu"
/>
<ListBoxItem Name = "listBoxItem3"
Content = "周 星"
/>
</ ListBox>
<Button Name = "button"
Content = "Save"
Grid.Column = "3"
Grid.Row = "6"
HorizontalAlignment = "Stretch"
VerticalAlignment = "Stretch"
/>
</ Grid>
Background operations of the preceding controls:
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: two buttons share one click event.
This method can be used for similar event operations.
private void button_Click(object sender, RoutedEventArgs e){
Button myButton=(Button)sender;
textBlock.Text=myButton.Name;
}