2

我想为从屏幕右边缘进入的窗口设置动画。

这是我的xml

<Window x:Class="SidebarTest.DockWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="DockWindow" Width="275"         
    ShowInTaskbar="False" 
    WindowStyle="None" ResizeMode="NoResize"
    AllowsTransparency="True" Background="Transparent" >

<Window.Triggers>
    <EventTrigger RoutedEvent="Window.Loaded">
        <BeginStoryboard>
            <Storyboard >
                <DoubleAnimation Duration="0:0:1.5" Storyboard.TargetProperty="Width" From="0" To="275" AccelerationRatio=".1"/>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</Window.Triggers>

<Grid Background="#2F2F2F">

</Grid>

但它动画宽度从左到右而不是从右到左。像这样:

在此处输入图像描述 在此处输入图像描述

我怎样才能改变它,让它从边缘进来?

4

4 回答 4

3

在您的代码隐藏中,

public DockWindow()
    {
        InitializeComponent();
        this.Left = this.Width + SystemParameters.FullPrimaryScreenWidth;
    }

将触发器更改为

<Window.Triggers>
    <EventTrigger RoutedEvent="Window.Loaded">
        <BeginStoryboard>
            <Storyboard >
                <DoubleAnimation Duration="0:0:1.5" Storyboard.TargetProperty="Left"  To="10" AccelerationRatio=".1"/>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</Window.Triggers>
于 2013-11-29T12:55:06.023 回答
1

我可能建议不要尝试缩放宽度,而是将宽度固定并将 aTranslateTransform应用于Window自身,实际上是从屏幕外将其滑入。下面提供了一个快速而肮脏的示例,您可能希望使用X坐标值和KeyTime以获得恰到好处的效果,但希望这对您有所帮助。干杯

<Window.RenderTransform>
    <TranslateTransform x:Name="SlideTheThingy" X="1000" />
</Window.RenderTransform>
<Window.Triggers>
  <EventTrigger RoutedEvent="Window.Loaded">
     <BeginStoryboard>
        <Storyboard>
           <DoubleAnimationUsingKeyFrames Storyboard.TargetName="SlideTheThingy"
                                          Storyboard.TargetProperty="X">
               <SplineDoubleKeyFrame KeyTime="0:0:1.25" Value="0" />
           </DoubleAnimationUsingKeyFrames>
        </Storyboard>
     </BeginStoryboard>
  </EventTrigger>
</Window.Triggers>
于 2014-05-02T14:05:35.713 回答
0

窗户位于其左上角。因此,当您为宽度设置动画并且位置保持不变时,窗口自然会向右增长

为了获得您想要的效果,您还需要使用该.Left属性为 Window 的位置设置动画。如果要将窗口捕捉到屏幕右侧并从那里滑入,则需要使用Left与屏幕宽度(和零像素宽度)匹配的值开始制作动画,然后制作动画到screenWidth - finalWidthOfWindow.

于 2013-11-29T12:53:43.773 回答
0

我实际上想通了,我需要将水平对齐设置在我想要为其大小设置动画的组件的右侧。它就像一个魅力!

于 2014-04-27T07:39:25.223 回答