我有一个问题得到和事件处理程序工作的按钮。我使用Visual Studio 2015年我的代码及以下的错误是:WPF C#按钮事件处理程序不工作
XAML:
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApplication1" mc:Ignorable="d" Title="MainWindow" Height="500" Width="983.334">
.
.
.
<Button x:Name="Button1" Content="Database" HorizontalAlignment="Left"
Margin="10,427,0,0" VerticalAlignment="Top" Width="99"
Click="Button1_Click"/>
背后代码:
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Test");
}
}
}
Error: CS1061 'MainWindow' does not contain a definition for 'Button1_Click' and no extension method 'Button1_Click' accepting a first argument of type 'MainWindow' could be found (are you missing a using directive or an assembly reference?)
每当我添加一个按钮,然后单击事件处理程序部分,这是我看到:文档项目没有代码隐藏文件。在添加事件处理程序之前添加代码隐藏文件和类定义。
任何帮助,将不胜感激。
你能后开''元素和属性从你的XAML文件? –
MickyD
' –
CausedByMonkey
谢谢,通常会将[编辑](http://stackoverflow.com/posts/38709809/edit)它。我已经为你做了:) – MickyD