環境: Windows Phone 7
画像を移動・拡縮する際のパターン
private void img_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
Image img = (Image)sender;
// 水平・垂直方向の移動
var tx = e.DeltaManipulation.Translation.X;
var ty = e.DeltaManipulation.Translation.Y;
img.Margin = new Thickness(tx, ty, 0, 0);
// 拡大縮小
var max = Math.Max(
e.DeltaManipulation.Scale.X,
e.DeltaManipulation.Scale.Y);
var min = Math.Min(
e.DeltaManipulation.Scale.X,
e.DeltaManipulation.Scale.Y);
var scale = (max > 1.0) ? max : min;
if (scale < 0)
return;
var newWidth = img.Width * scale;
var newHeight = img.Height * scale;
// 小さすぎる場合は触れなくなるので、ある程度大きさで縮小中止。
// 大きすぎる場合(2000px以上)は、処理が遅くなるので、拡大中止。
if (newWidth < 320 || newHeight < 240 || newWidth > 2000 || newHeight > 2000)
return;
img.Width = newWidth;
img.Height = newHeight;
}
コメントを残す