我正在按钮点击动态添加画布中的图像,并使用以下代码翻译这些图像:
private void Image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Image m = new Image();
m.Source = (sender as Image).Source;
m.Height = 110; m.Width = 110;
wid = Convert.ToInt16(canvas1.ActualWidth - m.Width);
hit = Convert.ToInt16(canvas1.ActualHeight - m.Height);
AddManipulableElement(m);
}
private void AddManipulableElement(UIElement element)
{
ManipulableContainer container = new ManipulableContainer();
container.Content = element;
canvas1.Children.Add(container);
}
public class ManipulableContainer : ContentControl
{
private CompositeTransform _transform;
public ManipulableContainer()
{
this.Loaded += ManipulableContainer_Loaded;
}
private void ManipulableContainer_Loaded(object sender, EventArgs e)
{
_transform = new CompositeTransform();
this.RenderTransform = _transform;
}
protected override void OnManipulationStarted(ManipulationStartedEventArgs e)
{
base.OnManipulationStarted(e);
e.Handled = true;
}
protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
{
base.OnManipulationDelta(e);
_transform.TranslateX += e.DeltaManipulation.Translation.X;
_transform.TranslateY += e.DeltaManipulation.Translation.Y;
if (_transform.TranslateX > wid)
{
_transform.TranslateX = wid;
}
if (_transform.TranslateY > hit)
{ _transform.TranslateY = hit; }
if (_transform.TranslateY < 0)
{ _transform.TranslateY = -_transform.TranslateY; }
if (_transform.TranslateX < 0)
{ _transform.TranslateX = -_transform.TranslateX; }
e.Handled = true;
}
protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e)
{
base.OnManipulationCompleted(e);
e.Handled = true;
}
}
一切都很好。现在我想通过手指添加放大/缩小和旋转功能到这些图像。
答案 0 :(得分:0)
您可以将此库用于多种功能:https://multitouch.codeplex.com
无论如何,你可以使用这篇文章作为参考:How to zoom in and zoom out Images in WP7?