C# WPF中的窗口显示事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9191256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 06:19:03 来源:igfitidea点击:
Window shown event in WPF?
提问by Poma
I want to apply fade animation every time my window is shown. How to do that from xaml? That window can be hidden and then shown again so I can't use Loadedevent.
每次显示窗口时,我都想应用淡入淡出动画。如何从 xaml 做到这一点?该窗口可以隐藏然后再次显示,因此我无法使用 Loaded事件。
回答by ezolotko
You can use the ContentRendered event or override OnContentRendered virtual method like this:
您可以使用 ContentRendered 事件或覆盖 OnContentRendered 虚拟方法,如下所示:
bool _shown;
protected override void OnContentRendered(EventArgs e)
{
base.OnContentRendered(e);
if (_shown)
return;
_shown = true;
// Your code here.
}

