可能重复:
程序在最小化后未从任务栏检索
背景 - 我有一个 ListBox,每个项目都包含几个按钮。单击按钮时,我希望标签与消息一起显示,然后淡出。我有一种方法来处理设置内容,使其可见,然后使用故事板将其淡出(见下文)。
这第一次工作正常,但是在同一个列表框项目中的任何进一步单击都不会导致任何事情发生 - 调试显示内容正在更改等,但控件永远不会变得可见。谁能指出我缺少的明显的东西(或者,一种可行的方式)?
private void SetLabelMessageContent(Panel panel, string message)
{
Label lblMessage = panel.Children.OfType<Label>().First();
if (lblMessage != null)
{
// Set content and make sure its visible
lblMessage.Content = message;
lblMessage.Visibility = Visibility.Visible;
lblMessage.Opacity = 1.0;
// Set the storyboard going - will fade it out
var storyboard = lblMessage.FindResource("MessageFadeOut");
if (storyboard is Storyboard)
{
((Storyboard)storyboard).Clone().Begin(lblMessage);
}
}
}
MessageFadeOut 资源是:
<Storyboard x:Key="MessageFadeOut">
<DoubleAnimation BeginTime="0:0:2.0" Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:0.25"/>
<ObjectAnimationUsingKeyFrames BeginTime="0:0:2.25" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Hidden</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>