简体   繁体   English

Visual Studio 2008中的WPF事件处理程序?

[英]WPF event handler in Visual Studio 2008?

When i went to add an event to the button which i dragged and dropped from toolbox to the window, the event handler on the properties window was not visible.. because of this reason, i added the event manually (by typing). 当我将事件添加到从工具箱拖放到窗口的按钮上时,属性窗口上的事件处理程序不可见..由于这个原因,我手动添加了事件(通过键入)。 but after when i built it and pressed F5, the button was not firing the event. 但是当我建造它并按下F5之后,该按钮没有触发该事件。

here is a little example that must be work ;-) 这是一个必须工作的小例子;-)

<Window x:Class="WpfStackOverflowSpielWiese.Window8"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window8"
        Height="300"
        Width="300">
  <Grid>
    <Button Click="Button_Click" />
  </Grid>
</Window>

code behind 背后的代码

using System.Windows;

namespace WpfStackOverflowSpielWiese
{
  /// <summary>
  /// Interaction logic for Window8.xaml
  /// </summary>
  public partial class Window8 : Window
  {
    public Window8() {
      InitializeComponent();
    }

    private void Button_Click(object sender, RoutedEventArgs e) {
      // do something....
    }
  }
}

hope that helps you... 希望对您有帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM