2011-07-21 46 views
0

我在WPF中製作了一個簡單的窗口(就像Overwolf),在Overwolf中屏幕的左上角有一個圓圈,當你拖動它時,它會以簡單的方式回到角落動畫。 所以我試圖在LeftProperty上使用DoubleAnimation製作同樣的效果,但它只能使用一次(第一次拖動它的工作,第二次只是你拖動它的地方)。DragMove如何工作? (它改變了哪些屬性)

我的XAML:

<Window x:Class="Overwoof.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" 
    Name="Main" 
    Width="200" 
    Height="200" 
    AllowsTransparency="True" 
    WindowStyle='None' 
    IsHitTestVisible="True" 
    Topmost="True" 
    Background="Transparent" 
    MouseLeftButtonUp="onDragLeave" 
    WindowStartupLocation="Manual"> 
<Grid IsHitTestVisible="True" Name="mainGrid" MinHeight="200" MinWidth="200"> 
    <Ellipse MouseLeftButtonDown="DragStart" Name="logo" Width="100" Height="100" Fill="Red" Opacity="0.5" Margin="12,24,66,37" IsManipulationEnabled="True" /> 
</Grid> 

我的C#代碼:

private void DragStart(object sender, MouseEventArgs e) 
    { 
     Main.DragMove(); 
    } 

    private void onDragLeave(object sender, MouseEventArgs e) 
    { 
     DoubleAnimation da = new DoubleAnimation(); 
     da.From = Main.Left; 
     da.To = -20; 
     da.Duration = new Duration(TimeSpan.FromSeconds(0.2)); 
     da.Completed += new EventHandler(AnimationCompleted); 
     Main.BeginAnimation(Window.LeftProperty, da); 
    } 

THX,BBLN。

回答

1

變化da.To = -20;da.To -= 20;

+0

這是沒有問題的,我現在的工作。 只需添加「Main.BeginAnimation(Window.LeftProperty,null);」在DragMove之前。 (失敗:D) – BBLN

相關問題