下面的xaml代码在窗口中运行良好。
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard Duration="00:00:2" Storyboard.TargetProperty="Opacity">
<DoubleAnimation From="0" To="1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
我的WPF应用程序中有五个WPF窗口。
我不想把上面的代码放到每一个WPF窗口。
那么,如何把上面的代码放到Application.Resources中,以便在5个窗口上工作呢?
发布于 2018-02-21 20:43:14
首先,让我们从触发器中开发一个合适的Style:
<Style TargetType="{x:Type Window}">
<Style.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard Duration="00:00:2" Storyboard.TargetProperty="Opacity">
<DoubleAnimation From="0" To="1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>此样式可以放在应用程序资源中。
现在的问题是,您的窗口不使用来自资源的默认样式,因此需要显式地应用它(有关更多详细信息,请参阅How to set default WPF Window Style in app.xaml? )
<Window ... Style="{StaticResource {x:Type Window}}">https://stackoverflow.com/questions/48906063
复制相似问题