Hi touhou_fantasy,
从你的描述,不太清楚是什么原因。 我建议你可以尝试使用 NotifyIcon 来实现程序最小化和显示。 你可以参考下面简单的代码。
WindowState ws;
WindowState wsl;
NotifyIcon notifyIcon;
public WPFwindowsshowhide()
{
InitializeComponent();
icon();
wsl = WindowState;
}
private void icon()
{
this.notifyIcon = new NotifyIcon();
this.notifyIcon.BalloonTipText = "你好,程序开启";
this.notifyIcon.Text = "程序--运行中";
this.notifyIcon.Icon = new System.Drawing.Icon("favicon.ico");
this.notifyIcon.Visible = true;
notifyIcon.MouseDoubleClick += OnNotifyIconDoubleClick;
this.notifyIcon.ShowBalloonTip(500);
}
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)
{
this.Hide();
}
}
Best Regards,
Yohann Lu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.