本文介绍了使图标闪烁WPF应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个图标.
imgstop.Visibility = System.Windows.Visibility.Visible;
如何使图标显示为闪烁?
How can I make the icon to be appear to be blinking ?
我尝试了以下代码:
public void blinkIconStopHide()
{
blinkTimerStop.Enabled = true;
blinkTimerStop.Interval = 15000;
imgstop.Visibility = System.Windows.Visibility.Hidden;
blinkTimerStop.Elapsed += new System.Timers.ElapsedEventHandler(tick_to_hideStop);
}
private void tick_to_hideStop(object sender, EventArgs e)
{
blinkIconStopShow();
}
public void blinkIconStopShow()
{
blinkTimerStop.Enabled = true;
blinkTimerStop.Interval = 15000;
imgstop.Visibility = System.Windows.Visibility.Visible;
blinkTimerStop.Elapsed += new System.Timers.ElapsedEventHandler(tick_to_showStop);
}
private void tick_to_showStop(object sender, EventArgs e)
{
blinkIconStopHide();
}
但是屏幕上似乎没有任何闪烁.
But nothing seems to be blinking on the screen.
推荐答案
以下代码将通过切换可见性使您的Icon每秒闪烁一次.通过更改DispatcherTimer的时间间隔,您可以更快或更慢地闪烁图标.
The following code will let your Icon blink each second by toggeling visibility. By changing the Interval of the DispatcherTimer you can blink the icon faster or slower.
DispatcherTime _blinkTimer = new DispatcherTimer();
public void StartBlinking() {
_blinkTimer.Interval = TimeSpan.FromSeconds(1);
_blinkTimer.Elapsed += ToggleIconVisibility;
_blinkTimer.Start();
}
public void StopBlinking() {
_blinkTimer.Stop();
_blinkTimer.Elapsed -= ToggleIconVisibility;
}
private void ToggleIconVisibility(object sender, EventArgs e)
{
imgstop.Visibility = !imgstop.Visibility;
}
这篇关于使图标闪烁WPF应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!