我知道这个问题已经提出,但提供的解决方案(such as this)对我来说还不够。
我想最小化我的应用程序窗口,如下所示:
这些是我的代码(不必要的代码没有张贴):XAML
:
<Window x:Name="GanjAsemanMainWindow" x:Class="Ganj_Aseman.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:Ganj_Aseman"
mc:Ignorable="d"
Loaded="GanjAsemanMainWindow_Loaded" AllowsTransparency="True" Background="Transparent" FontSize="13" Height="535" ResizeMode="CanResizeWithGrip" Title="MainWindow" Width="764" WindowStyle="None">
<Window.RenderTransform>
<RotateTransform CenterX="{Binding}" CenterY="{Binding}" Angle="{Binding}"/>
</Window.RenderTransform>
<Window.Resources>
<Storyboard x:Key="WindowRotation">
<DoubleAnimation BeginTime="00:00:00" SpeedRatio="0.9" Duration="00:00:2" Storyboard.TargetName="GanjAsemanMainWindow" From="0" To="360" AutoReverse="False" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"/>
</Storyboard>
</Window.Resources>
<Grid>
<Image x:Name="MinimizeIconImage" PreviewMouseLeftButtonDown="MinimizeIconImage_PreviewMouseLeftButtonDown" MouseEnter="MinimizeIconImage_MouseEnter" MouseLeave="MinimizeIconImage_MouseLeave" GotFocus="MinimizeIconImage_GotFocus" LostFocus="MinimizeIconImage_LostFocus" Focusable="True" FocusVisualStyle="{x:Null}" Cursor="Hand" Height="47" VerticalAlignment="Top" Source="{Binding}" Margin="0,2,67,0" HorizontalAlignment="Right" Width="52">
<Image.Triggers>
<EventTrigger RoutedEvent="PreviewMouseLeftButtonDown">
<BeginStoryboard>
<Storyboard>
<ParallelTimeline BeginTime="00:00:00" SpeedRatio="0.9" Storyboard.TargetName="GanjAsemanMainWindow">
<DoubleAnimation Duration="00:00:2" From="{Binding Path=ActualHeight,ElementName=GanjAsemanMainWindow}" To="0" AutoReverse="False" Storyboard.TargetProperty="Height"/>
<DoubleAnimation Duration="00:00:2" From="{Binding Path=ActualWidth,ElementName=GanjAsemanMainWindow}" To="0" AutoReverse="False" Storyboard.TargetProperty="Width"/>
<DoubleAnimation Duration="00:00:2.5" From="100" To="0" AutoReverse="False" Storyboard.TargetProperty="Opacity"/>
</ParallelTimeline>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
</Grid>
C#
:
private void MinimizeIconImage_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
RotateTransform RT = new RotateTransform(0, ActualWidth / 2, ActualHeight / 2);
GanjAsemanMainWindow.RenderTransform = RT;
(Resources["WindowRotation"] as Storyboard).Begin();
}
但是,DoubleAnimations
是顺序执行的,而不是并行执行的,因此,获得以下输出:
我认为,如果我们能将三个属性绑定到一个Storyboard.TargetProperty
,它将工作得很好。
我使用以下工具:
.NET Framework 4.5
WPF
感谢您抽出宝贵时间。
顺祝商祺!
礼萨·贾费里
1条答案
按热度按时间bwitn5fc1#
您也可以制作一个
ScaleTransform
的动画,而不是制作Window的Width
和Height
的动画,类似于您已经拥有的RotateTransform
。不过,您必须设定Window的
RenderTransformOrigin
属性。下面是一个最简单的例子: