在代码层我写入
using System;
using System.Windows;
using System.Windows.Forms;
namespace WpfApplication5
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
WindowState ws;
WindowState wsl;
NotifyIcon notifyIcon;
public Window1()
{
InitializeComponent();
//显示托盘。
icon();
//保证窗体显示在上方。
wsl = WindowState;
}
private void OnNotifyIconDoubleClick(object sender, EventArgs e)
{
this.Show();
WindowState = wsl;
}
private void Window_StateChanged(object sender, EventArgs e)
{
ws = WindowState;
if (ws == WindowState.Minimized)
{
Hide();
}
}
private void icon()
{
this.notifyIcon = new NotifyIcon();
this.notifyIcon.BalloonTipText = "Hello, NotifyIcon!";
this.notifyIcon.Text = "Hello, NotifyIcon!";
this.notifyIcon.Icon = new System.Drawing.Icon("NotifyIcon.ico");
this.notifyIcon.Visible = true;
notifyIcon.MouseDoubleClick += OnNotifyIconDoubleClick;
this.notifyIcon.ShowBalloonTip(1000);
}
}
}
表现层代码:
<Window x:Class="WpfApplication5.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">
</Window>
但为什么我运行时出现这样的错误
未处理 System.Windows.Markup.XamlParseException
Message="无法创建在程序集“WpfApplication5, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”中定义的“Window1”的实例。 调用的目标发生了异常。 标记文件中“Window1.xaml”行1位置9处的错误。"
Source="PresentationFramework"
LineNumber=1
LinePosition=9