C# WPF窗口在拖动后报告旧的左属性
因此我遇到了这个问题,在调用DragMove()之后,窗口会报告其旧的C# WPF窗口在拖动后报告旧的左属性,c#,.net,wpf,C#,.net,Wpf,因此我遇到了这个问题,在调用DragMove()之后,窗口会报告其旧的Left属性,就好像DragMove根本没有更改它一样 假设窗口的左侧当前为100像素, 我使用DragMove()移动窗口: 然后单击按钮,显示窗口的新左侧位置: private void SomeButton_Click(object sender, RoutedEventArgs e) { MessageBox.Show(Left.ToString()); } 然而,消息框仍然显示“100”,似乎窗口根
Left
属性,就好像DragMove根本没有更改它一样
假设窗口的左侧当前为100像素,
我使用DragMove()移动窗口:
然后单击按钮,显示窗口的新左侧位置:
private void SomeButton_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(Left.ToString());
}
然而,消息框仍然显示“100”,似乎窗口根本没有移动,尽管它确实移动了
我遗漏了什么?我发现了问题,我正在设置
Left
属性的动画,出于某种原因,Left
即使在使用DragMove()移动窗口后仍会报告相同的后期动画值
为了让它工作,我必须在动画完成后从窗体中删除动画,如下所示:
DoubleAnimation _leftAnimation = new DoubleAnimation();
//...animation settings...
_leftAnimation.Completed += delegate(object animSender, EventArgs animE)
{
BeginAnimation(Window.LeftProperty, null);
};
this.BeginAnimation(LeftProperty, _leftAnimation);
在类似的测试项目中,我的值似乎在更新,您是否在其他地方定义了
Left
,或者您的按钮位于另一个具有Left
属性的控件中?我发现了问题,我正在设置Left属性的动画,它似乎一直停留在该值上,完成后必须重置动画。。。谢谢你的关注
DoubleAnimation _leftAnimation = new DoubleAnimation();
//...animation settings...
_leftAnimation.Completed += delegate(object animSender, EventArgs animE)
{
BeginAnimation(Window.LeftProperty, null);
};
this.BeginAnimation(LeftProperty, _leftAnimation);