我想通過手勢來移動/縮放/旋轉用戶控件,並且我希望旋轉和縮放的中心點位於手勢的中心(例如,當使用兩個手指旋轉,手指之間的點應該是旋轉的中心)。圍繞手勢點旋轉/縮放
當我不試圖設置旋轉/縮放的中心點或設置一個靜態點時,一切都按預期工作。將CompositeTransform.CenterX/Y設置爲ManipulationDeltaRoutedEventArgs.Position的值時,usercontrol將隨着每個手勢更加錯誤的中心點旋轉,並偶爾會加速。
我使用的是CompositeTransform作爲渲染變換我的用戶控制的,我已經迷上了在ManipulationDelta事件,像這樣:
private void UserControl_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
//this.transform is my composite transform
//which is set to be the render transform of the user control
this.transform.CenterX = e.Position.X;
this.transform.CenterY = e.Position.Y;
this.transform.ScaleX *= e.Delta.Scale;
this.transform.ScaleY *= e.Delta.Scale;
this.transform.Rotation += e.Delta.Rotation;
this.transform.TranslateX += e.Delta.Translation.X;
this.transform.TranslateY += e.Delta.Translation.Y;
}
看來,e.Position不給我我想要什麼,不幸的是文檔非常簡短,只能說明Gets the point from which the manipulation originated.從我的調試打印中看來,CompositeTransform.CenterX/Y和ManipulationDeltaRoutedEventArgs.Position都位於用戶控件的座標系中。