- <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>
- <Button x:Name="But1" Content="点我" HorizontalAlignment="Left" Height="40" Margin="200,150,0,0" VerticalAlignment="Top" Width="125" Click="OnClick"/>
- </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();
- MakeButton();
- }
- public void MakeButton()
- {
- Button But1 = new Button();
- But1.AddHandler(Button.ClickEvent, new RoutedEventHandler(OnClick));
- }
- public void OnClick(object sender, RoutedEventArgs e)
- {
- But1.Content = "Hello World !";
- }
- }
- }
复制代码 |