48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Markup;
|
|
|
|
namespace WPF基础_1_1_只使用代码方式创建;
|
|
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
private Button? _button;
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
InitializeComponent1();
|
|
}
|
|
|
|
private void InitializeComponent1()
|
|
{
|
|
Width = Height = 285;
|
|
Left = Top = 100;
|
|
Title = "只使用代码创建";
|
|
|
|
// 创建面板
|
|
// var panel = new DockPanel();
|
|
var panel = ContainerGrid;
|
|
|
|
// 创建按钮
|
|
_button = new Button();
|
|
_button.Content = "点击我";
|
|
_button.Margin = new Thickness(30);
|
|
_button.Click += Button_OnClick;
|
|
|
|
// 添加元素
|
|
IAddChild container = panel;
|
|
container.AddChild(_button);
|
|
|
|
// container = this;
|
|
// container.AddChild(panel);
|
|
}
|
|
|
|
private void Button_OnClick(object sender, RoutedEventArgs eventArgs)
|
|
{
|
|
_button!.Content = "栓Q";
|
|
}
|
|
} |