1
我想使用縮放手勢也與WPFExtensions.Controls.ZoomControl
放大。在此基礎上answerWPFExtensions zoomControl可 - 雙指縮放是跳躍
- 我知道如何檢測縮放手勢。我用它作爲成員_detector
。我使用ZoomControl.ManipulationDelta
來進行縮放。
所以我想我只是把ManipulationDelta
和縮小這樣的:
private void AssociatedObject_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
if (_detector.IsScalingAllowed) // this just tells me if it is a pinch gesture or not
{
if ((e.DeltaManipulation.Scale.X < 1)
|| (e.DeltaManipulation.Scale.X > 1))
{
//AssociatedObject is ZoomControl
AssociatedObject.Zoom = Math.Max(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.Y);
}
}
}
但這隻會讓我ZoomControl
變焦相當有窮人和回跳。
我的完整代碼如下所示:
public class ZoomBoxBehaviour : Behavior<ZoomControl>
{
private GestureDetector _detector;
protected override void OnAttached()
{
base.OnAttached();
if (AssociatedObject != null)
{
_detector = new GestureDetector(AssociatedObject);
if (!AssociatedObject.IsManipulationEnabled) AssociatedObject.IsManipulationEnabled = true;
AssociatedObject.ManipulationDelta += AssociatedObject_ManipulationDelta;
}
}
protected override void OnDetaching()
{
if (AssociatedObject != null)
{
AssociatedObject.ManipulationDelta -= AssociatedObject_ManipulationDelta;
}
base.OnDetaching();
}
private void AssociatedObject_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
if (_detector.IsScalingAllowed) // this just tells me if it is a pinch gesture or not
{
if ((e.DeltaManipulation.Scale.X < 1)
|| (e.DeltaManipulation.Scale.X > 1))
{
AssociatedObject.Zoom = Math.Max(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.Y);
}
}
}
}
你可以從第一個答案的GestureDetector
here。
UPDATE
我把它適當地放大到中心
private void AssociatedObject_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
if (_detector.IsScalingAllowed) // this just tells me if it is a pinch gesture or not
{
if ((e.DeltaManipulation.Scale.X < 1)
|| (e.DeltaManipulation.Scale.X > 1))
{
AssociatedObject.Zoom = Math.Max(e.CumulativeManipulation.Scale.X, e.CumulativeManipulation.Scale.Y);
//Size newSize = new Size(AssociatedObject.ZoomBox.Size.Width * e.CumulativeManipulation.Scale.X,
// AssociatedObject.ZoomBox.Size.Height * e.CumulativeManipulation.Scale.Y);
//AssociatedObject.ZoomTo(new Rect(new Point(0,0), newSize));
}
}
}
但現在我要放大我的手勢的中心,但這個評論code
只會放大到最大....爲什麼?