Bind event handler to button with RoutedEventHandler
<Window
x:Class="WpfApplication1.StackPanelDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Stack Panel Demo">
<StackPanel>
<Button x:Name="canvasButton">Canvas Demo</Button>
</StackPanel>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
namespace WpfApplication1 {
public partial class StackPanelDemo : Window {
public StackPanelDemo() {
InitializeComponent();
this.canvasButton.Click += new RoutedEventHandler(canvasButton_Click);
}
void canvasButton_Click(object sender, RoutedEventArgs e) {
Console.WriteLine("clicked");
}
}
}
Related examples in the same category