title: Strange behavior when using lambda expression on WPF buttons click event
body: <p>My problem is hard to explain, so I created an example to show here.</p>
  
  <p>When the WPF window in the example below is shown, three buttons are displayed, each one with a different text.</p>
  
  <p>When anyone of these buttons is clicked, I assume its text should be displayed in the message, but instead, all of them display the same message, as if all of them were using the event handler of the last button.</p>
  
  <pre><code>public partial class Window1 : Window {
      public Window1() {
          InitializeComponent();
          var stackPanel = new StackPanel();
          this.Content = stackPanel;
          var n = new KeyValuePair&lt;string, Action&gt;[] { 
              new KeyValuePair&lt;string, Action&gt;("I", () =&gt; MessageBox.Show("I")), 
              new KeyValuePair&lt;string, Action&gt;("II", () =&gt; MessageBox.Show("II")), 
              new KeyValuePair&lt;string, Action&gt;("III", () =&gt; MessageBox.Show("III"))
          };
          foreach (var a in n) {
              Button b = new Button();
              b.Content = a.Key;
              b.Click += (x, y) =&gt; a.Value();
              stackPanel.Children.Add(b);
          }
      }
  }
  </code></pre>
  
  <p>Does anyone know what is wrong?</p>