拖动移动如何工作? (它改变了哪些属性?)
我正在 WPF 中制作一个简单的窗口(如 Overwolf),在 Overwolf 中,屏幕左上角有一个圆圈,当您拖动它时,它会通过简单的动画移回到角落。 因此,我尝试在 LeftProperty 上使用 DoubleAnimation 来实现相同的效果,但它只能工作一次(第一次拖动其工作,第二次它只是停留在您拖动的位置 )。
我的 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);
}
谢谢,BBLN。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
da.To = -20;
更改为da.To -= 20;
change
da.To = -20;
toda.To -= 20;