我想实现一个状态栏,我将能够在指定的时间段内显示消息,之后它们将淡出。
这可以用 wpf 中任何现成的控件来完成吗?我在 StatusBar 中找不到这样的功能,据我所知,它是其他项目的容器。
有什么建议吗?
最佳答案
StatusBar
确实只是其他项目的容器。
我认为没有这样的内置功能。</p>
但是你可以使用 Timer
实现你想要的。
创建一个将文本消息设置为 StatusBarItem
内容的方法,在 Timer
和 Timer.Elapsed
中设置时间> 您从 StatusBarItem
中删除文本的事件。
状态栏
XAML:
<StatusBar Height="25" Margin="5">
<StatusBarItem x:Name="StatusMessage" />
</StatusBar>
程序代码:
private void ShowStatusMessage(string message)
{
StatusMessage.Content = message;
var timer = new System.Timers.Timer();
timer.Interval = 2000; //2 seconds
timer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
{
//stop the timer
timer.Stop();
//remove the StatusMessage text using a dispatcher, because timer operates in another thread
this.Dispatcher.BeginInvoke(new Action(() =>
{
StatusMessage.Content = "";
}));
};
timer.Start();
}
如果你想要动画你应该寻找DoubleAnimation
关于c# - StatusBar 消息实现超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14383494/