菜鸟求助!"TestForWpf.mainWindow"不包含"button1_Click"的定义,并且找不到可接受类型为"TestForWpf.mainWi

Joanna_yan 2012-05-18 03:37:31
我用的是VS2010的WPF。。。

这是从网上找的,但是这个错误是为什么啊?
"TestForWpf.mainWindow"不包含"button1_Click"的定义,并且找不到可接受类型为"TestForWpf.mainWindow"的第一个参数的扩展方法“button1_Click”(是否缺少 using 指令或程序集引用?)

MainWindow.xaml

<Window x:Class="TestForWpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="517" Width="842" Background="White" WindowStartupLocation="CenterScreen">
<Grid>
<Button Content="Pop up" Height="23" HorizontalAlignment="Left" Margin="58,38,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
</Window>


MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace aaa
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void InitializeComponent()
{
throw new NotImplementedException();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
PopupWindow win = new PopupWindow();
win.Show();
}
}
}


这是要弹出的窗口

<Window x:Class="TestForWpf.PopupWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="PopupWindow" Height="211" Width="401" ResizeMode="NoResize" WindowStyle="None" WindowStartupLocation="CenterScreen">
<Grid Background="#dedede" Height="152" Width="359">
<Label Margin="46,44,54,54" Height="40" Content="This is a self-closing window!" VerticalContentAlignment="Bottom" FontSize="18" FontWeight="Bold"></Label>
</Grid>
</Window>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Timers;
using System.Windows.Threading;

namespace aaa
{
/// <summary>
/// Interaction logic for PopupWindow.xaml
/// </summary>
public partial class PopupWindow : Window
{
private Timer timer = new Timer(3000);
public PopupWindow()
{
InitializeComponent();

timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Start();
}

private void InitializeComponent()
{
throw new NotImplementedException();
}

void timer_Elapsed(object sender, ElapsedEventArgs e)
{
timer.Stop();
Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate()
{
this.Hide();
});
}
}
}

...全文
1028 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2012-05-18
  • 打赏
  • 举报
回复
TestForWpf
应该改成
aaa吧

名称空间不一致

17,747

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧