.xaml 的定义如下:
<Window x:Class="WPF_APP.TheBasics"
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"
xmlns:local="clr-namespace:WPF_APP"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="TheBasics" Height="750" Width="400">
<Grid>
<Border Padding="10">
<StackPanel>
<!--Buttons-->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="ApplyButton" Click="ApplyButton_Click" Margin ="0,0,10,0" Grid.Column="0" Content="Apply"></Button>
<Button x:Name="ResetButton" Click="ResetButton_Click" Grid.Column="1" Content="Reset"></Button>
<Button x:Name="RefreshButton" Margin ="10 0 0 0" Grid.Column="2" Content="Refresh"></Button>
</Grid>
<TextBlock Text="pulse Properties" FontWeight="Bold" Margin="0 10"/>
<!--Desctrption-->
<TextBlock Text="Desctrption"/>
<TextBox x:Name="DescriptionText" Padding="2"/>
<!--Status and Revise-->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--status-->
<StackPanel Grid.Column="0" Margin="0 0 10 0">
<TextBlock Text="Status"/>
<TextBox IsReadOnly="True" Background="#eee" Padding="2"/>
</StackPanel>
<StackPanel Grid.Column="1">
<TextBlock Text="Revision"/>
<TextBox IsReadOnly="True" Background="#eee" Padding="2"/>
</StackPanel>
</Grid>
<!--Part Number-->
<TextBlock Text="Part Number"/>
<TextBox IsReadOnly="True" Background="#eee" Padding="2"/>
<!--Raw Material-->
<TextBlock Text="Raw Material" FontWeight="Bold" Margin="0 10"/>
<!--Material-->
<TextBlock Text="Material"/>
<ComboBox Padding="2"/>
<!--Manufacturing Info-->
<TextBlock Text="Manufacturing Info" FontWeight="Bold" Margin="0 10"/>
<!--Work Centres-->
<TextBlock Text="Work Centres"/>
<!--CheckBoxs-->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--column1-->
<StackPanel Grid.Column="0" Margin="0 0 10 0">
<CheckBox Checked="Checkbox_checked" x:Name="WeldCheckBox" Content="Weld"/>
<CheckBox Checked="Checkbox_checked" x:Name="AssemblyCheckBox" Content="Assembly"/>
<CheckBox Checked="Checkbox_checked" x:Name="PlasmaCheckBox" Content="Plasma"/>
<CheckBox Checked="Checkbox_checked" x:Name="LaserCheckBox" Content="Laser"/>
<CheckBox Checked="Checkbox_checked" x:Name="PurchaseCheckBox" Content="Purchase"/>
</StackPanel>
<!--column2-->
<StackPanel Grid.Column="1">
<CheckBox Checked="Checkbox_checked" x:Name="LatheCheckBox" Content="Lathe"/>
<CheckBox Checked="Checkbox_checked" x:Name="DrillCheckBox" Content="Drill"/>
<CheckBox Checked="Checkbox_checked" x:Name="FoldCheckBox" Content="Fold"/>
<CheckBox Checked="Checkbox_checked" x:Name="RollCheckBox" Content="Roll"/>
<CheckBox Checked="Checkbox_checked" x:Name="SawCheckBox" Content="Saw"/>
</StackPanel>
</Grid>
<!--Length-->
<TextBlock Text="Length"/>
<TextBox x:Name="LengthText" Padding="2"/>
<!--Mass-->
<TextBlock Text="Mass"/>
<TextBox x:Name="MessText" IsReadOnly="True" Background="#eee" Padding="2"/>
<!--Finish-->
<TextBlock Text="Finish"/>
<ComboBox x:Name="FinishDropdown" SelectionChanged="FinishDropdown_SelectionChanged" SelectedIndex="0 " Padding="2">
<ComboBoxItem>Painted</ComboBoxItem>
<ComboBoxItem>Not Painted</ComboBoxItem>
</ComboBox>
<!--Purchase Info-->
<TextBlock Text="Purchase Infomation"/>
<ComboBox SelectedIndex="0 " Padding="2">
<ComboBoxItem>Rubber</ComboBoxItem>
<ComboBoxItem>Not Rubber</ComboBoxItem>
</ComboBox>
<!--Supplier Name-->
<TextBlock Text="Supplier Name"/>
<TextBox x:Name="SupplierNameText" TextChanged="SupplierNameText_TextChanged" Padding="2"/>
<!--Supplier Code-->
<TextBlock Text="Supplier Code"/>
<TextBox Padding="2"/>
<TextBlock Text="Additional Info" FontWeight="Bold" Margin="0 10"/>
<!--Note-->
<TextBlock Text="Note"/>
<TextBox x:Name="NoteText" Padding="2"/>
</StackPanel>
</Border>
</Grid>
</Window>
.cs 的定义如下:
using System.Windows;
using System.Windows.Controls;
namespace WPF_APP
{
/// <summary>
/// TheBasics.xaml 的交互逻辑
/// </summary>
public partial class TheBasics : Window
{
public TheBasics()
{
InitializeComponent();
}
private void ApplyButton_Click(object sender, RoutedEventArgs e)
{
//输出填写的内容
MessageBox.Show($"the description is:{this.DescriptionText.Text}");
}
private void ResetButton_Click(object sender, RoutedEventArgs e)
{
//取消勾选
this.WeldCheckBox.IsChecked = this.AssemblyCheckBox.IsChecked = this.PlasmaCheckBox.IsChecked = this.LaserCheckBox.IsChecked =
this.PurchaseCheckBox.IsChecked = this.LatheCheckBox.IsChecked = this.DrillCheckBox.IsChecked = this.FoldCheckBox.IsChecked =
this.RollCheckBox.IsChecked = this.SawCheckBox.IsChecked = false;
}
private void Checkbox_checked(object sender, RoutedEventArgs e)
{
//获取对象的内容
this.LengthText.Text += ((CheckBox)sender).Content;
}
private void FinishDropdown_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.NoteText == null)
return;
var combobox = (ComboBox)sender;
var value = (ComboBoxItem)combobox.SelectedValue;
this.NoteText.Text = (string)value.Content;
}
//窗口加载就执行事件
private void Window_Loaded(object sender, RoutedEventArgs e)
{
FinishDropdown_SelectionChanged(this.FinishDropdown, null);
}
private void SupplierNameText_TextChanged(object sender, TextChangedEventArgs e)
{
this.MessText.Text = this.SupplierNameText.Text;
}
}
}
最后,显示效果: