I am making a simple window in WPF (like Overwolf), in Overwolf there is a circle in the top-left of the screen and when you drag it, its moving back to the corner with simple Animation. So I tried to make the same effect using DoubleAnimation on the LeftProperty but it only works once (The first time you drag its working, the second its just stay where you dragged it).
My 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>
My C# code:
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.
change da.To = -20;
toda.To -= 20;
精彩评论