对于我的生活,我无法弄清楚为什么下面的简单设置不起作用。我只希望边框在加载后放大(“放大”),放大功能包含在资源样式中。但是当下面的 XAML 运行时,边框只是以 100% 的比例加载,没有动画发生。您的帮助将不胜感激!
<Style x:Key="SZoomIn" TargetType="FrameworkElement">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform/>
</Setter.Value>
</Setter>
<Style.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleX)">
<LinearDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
<LinearDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleY)">
<LinearDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
<LinearDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
<Style x:Key="SBorder" BasedOn="{StaticResource SZoomIn}" TargetType="Border">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
</Style>
<!-- ....... -->
<Border Style="{StaticResource SBorder}"/>
编辑:我没有在上面显示完整的标记,以便让事情保持简单,但我的完整标记在下面。请注意,由于边框内有按钮,因此边框在运行时确实具有高度/宽度。
<Window x:Name="StartWindow" x:Class="MEACruncher.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MEACruncher"
mc:Ignorable="d"
Title="MEA Cruncher" Height="393" Width="659" Margin="0" WindowState="Maximized">
<Window.Background>
<ImageBrush ImageSource="Resources/NeuronBackground.jpg" Stretch="UniformToFill"/>
</Window.Background>
<Window.Resources>
<SolidColorBrush x:Key="BabyBlue">#FF4D7EB8</SolidColorBrush>
<SolidColorBrush x:Key="BlackBkgrd">#B2000000</SolidColorBrush>
<Style x:Key="SBtn" TargetType="Button">
<Setter Property="Margin" Value="0,5"/>
<Setter Property="Background" Value="{StaticResource BabyBlue}"/>
<Setter Property="BorderBrush" Value="{x:Null}"/>
<Setter Property="Padding" Value="10,3"/>
<Setter Property="FontSize" Value="24"/>
</Style>
<Style x:Key="STopBtn" BasedOn="{StaticResource SBtn}" TargetType="Button">
<Setter Property="Margin" Value="0,0,0,5"/>
</Style>
<Style x:Key="SBottomBtn" BasedOn="{StaticResource SBtn}" TargetType="Button">
<Setter Property="Margin" Value="0,5,0,0"/>
</Style>
<Style x:Key="SZoomIn" TargetType="FrameworkElement">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform/>
</Setter.Value>
</Setter>
<Style.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleX)">
<LinearDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
<LinearDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="RenderTransform.(ScaleTransform.ScaleY)">
<LinearDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
<LinearDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
<Style x:Key="SBorder" BasedOn="{StaticResource SZoomIn}" TargetType="Border">
<Setter Property="BorderBrush" Value="{StaticResource BabyBlue}"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="Background" Value="{StaticResource BlackBkgrd}"/>
<Setter Property="CornerRadius" Value="5"/>
<Setter Property="Padding" Value="10"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
</Style>
<Style x:Key="SStackPnl" TargetType="StackPanel">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</Window.Resources>
<Border x:Name="MainBorder" Style="{StaticResource SBorder}">
<StackPanel x:Name="MainStackPnl" Style="{StaticResource SStackPnl}">
<Button x:Name="ViewProjectsBtn" Content="View Projects" Style="{StaticResource STopBtn}" Click="ViewProjectsBtn_Click"/>
<Button x:Name="AboutBtn" Content="About" Style="{StaticResource SBtn}" Click="AboutBtn_Click"/>
<Button x:Name="ExitBtn" Content="Exit" Style="{StaticResource SBottomBtn}" Click="ExitBtn_Click"/>
</StackPanel>
</Border>
</Window>