我想实现一个状态栏,我将能够在指定的时间段内显示消息,之后它们将淡出。
这可以通过 wpf 中的任何现成控件来完成吗?我在 StatusBar 中找不到这样的功能,据我所知,它是其他项目的容器。
有什么建议么?
StatusBar确实只是其他物品的容器。
我认为没有这样的内置功能。
但是您可以使用 aTimer来实现您想要的。
制作一个方法,将文本消息设置为 的内容,在StatusBarItem中设置时间,Timer如果Timer.Elapsed您从 中删除文本StatusBarItem。
StatusBarXAML:
<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
只需在进度条中绑定数据并在淡出时更新它。让我们知道更多细节以提供更好的解决方案