<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <TextBox Name="box1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" FontSize="24" Foreground="Blue" Height="50" Margin="20,134,345,136" RenderTransformOrigin="0.26,0.18">aaa</TextBox> <Button x:Name="btn" Click="btn_click" Content="Button" HorizontalAlignment="Left" Margin="201,149,0,0" VerticalAlignment="Top" Width="75"/> <TextBox Name="box2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" FontSize="24" Foreground="Blue" Height="50" Margin="340,134,25,136" RenderTransformOrigin="0.26,0.18"></TextBox> </Grid> </Window>
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplication1 { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } public void btn_click(object sender, RoutedEventArgs e) { box2.Text = "bbb"; } } }