My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
3 hours ago: If you are a developer in Berlin and need to improve your English, I'm looking for groups to teach after work: http://tanguay.info/itenglish.
5 hours ago: As far as I'm concerned, the singularity is already here, every time I wake up twitter tells me something amazing was created while I slept.
5 hours ago: We're not suffering from information overload, we're suffering from faulty filtering.
5 hours ago: Classic literature for free as nicely formatted 1-page or 2-page PDF downloads: http://www.planetebook.com/free-ebooks.asp.
5 hours ago: Yes, when you pour coffee, "a lightning storm of neuronal activity occurs almost across the entire brain": http://is.gd/eWO1T @pholdings.
22 hours ago: If you put two spaces after a period or use underlining for emphasis, you were born before 1980.
22 hours ago: Word of the day: infovore, n. an animal with a voracious appetite for information.
yesterday: It's said that on average people use less than 10% of their brain, but I think on average computers use less than 1% of their CPU.
2 days ago: Saturday fun: team drawing on two computers with six-year-old in a shared google doc diagram.
2 days ago: Someday I want to produce a developer podcast called "What's that?" but for now "the developer's life" is a nice genre: http://is.gd/eTURO.
3 days ago: Here's a use-case for datapod format, recording human-readable data that later can be used as a datasource: http://is.gd/eSsLg @pholdings.
WPF CODE EXAMPLE created on Tuesday, February 02, 2010 permalink
How to pass an event handler as a parameter
This example shows how you can pass an event handler into a method (here a constructor of a class) so that method or class can attach that method handler to controls, thus making "how to deal with a click event" something you can pass in as any other variable.
XAML:
<Window x:Class="TestDel234.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <StackPanel Margin="10" Orientation="Horizontal">
        <StackPanel x:Name="MainContentLeft"/>
        <StackPanel x:Name="MainContentRight"/>
    </StackPanel>
</Window>

Code Behind:
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;

namespace TestDel234
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            List<string> items = new List<string> { "one", "two", "three" };
            SmartGrid sg = new SmartGrid(MainContentLeft, items, DisplayHelpText1);
            SmartGrid sg2 = new SmartGrid(MainContentRight, items, DisplayHelpText2);
        }

        private void DisplayHelpText1(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("this is the help text for column 1");
        }

        private void DisplayHelpText2(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("this is the help text for column 2");
        }
    }

    public class SmartGrid
    {
        public SmartGrid(StackPanel sp, List<string> items, EventHandler<MouseButtonEventArgs> eventHandler)
        {
            foreach (var item in items)
            {
                TextBlock tb = new TextBlock();
                tb.Text = item;
                tb.MouseDown += new MouseButtonEventHandler(eventHandler);
                tb.Margin = new Thickness(10);
                tb.Cursor = Cursors.Hand;
                sp.Children.Add(tb);
            }
        }
    }
}
Jaydev: how to pass an event handler as parameter in vb.Net
need markup?