WPF:鼠標長時間無操作,窗口隱藏
//設置鼠標長時間無操作計時器
private System.Timers.Timer MouseTimerTick = new System.Timers.Timer(10000);
private void Window_Activated(object sender, EventArgs e)
{
this.Dispatcher.Invoke(new Action(() =>
{
//顯示
}));
MouseTimerTick.Stop();
}
private void Window_Deactivated(object sender, EventArgs e)
{
MouseTimerTick.Start();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
MouseTimerTick.Elapsed += new System.Timers.ElapsedEventHandler(TimerTick);
MouseTimerTick.AutoReset = true;
MouseTimerTick.Enabled = true;
}
private void TimerTick(object source, System.Timers.ElapsedEventArgs e)
{
this.Dispatcher.Invoke(new Action(() =>
{
//隱藏
}));
}
WPF:鼠標長時間無操作,窗口隱藏