I tried to make an example of the book that shows exactly
private Button button1;
public MainWindow()
{
InitializeComponent();
}
private void InitializeComponent()
{
// Configure the form.
this.Width = this.Height = 285;
this.Left = this.Top = 100;
this.Title = "Code-Only Window";
// Create a container to hold a button.
DockPanel panel = new DockPanel();
// Create the button.
button1 = new Button();
button1.Content = "Please click me.";
button1.Margin = new Thickness(30);
// Attach the event handler.
button1.Click += button1_Click;
// Place the button in the panel.
IAddChild container = panel;
container.AddChild(button1);
// Place the panel in the form.
container = this;
container.AddChild(panel);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
button1.Content = "Thank you.";
}
But it gives me an error:
"Type 'WpfApplication1.MainWindow' already defines a member called 'InitializeComponent' with the same parameter types"