问题
I can drag this pictures to right or left,up,down It passed over an screens.I had zoom in and out. I want limit about that. Using windows phone 8.1 app. After the transformation, brings the image back if it is out of the boundary. You can detect if the image is out of boundary by comparing the values of TranslateX/TranslateY and the width/height of the boundary. The boundary is the parent of the image (it is a Grid?), you need to debug the code to determine the boundary for TranslateX and TranslateY.
XAML
<Grid>
<Grid Name="container">
<Image Name="img_container" Source="/papers.co-mb00-baloon-fly-sea-wallpaper-1920x1080.jpg"
ManipulationDelta="Image_ManipulationDelta"
ManipulationMode="Scale,TranslateX,TranslateY"
Stretch="Uniform"
RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<CompositeTransform/>
</Image.RenderTransform>
</Image>
</Grid>
</Grid>
C#
int mincale = 1;
private void Image_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
Image img = sender as Image;
CompositeTransform ct = img.RenderTransform as CompositeTransform;
//zoom
ct.ScaleX *= e.Delta.Scale;
ct.ScaleY *= e.Delta.Scale;
//checking
if (ct.ScaleX < mincale)
ct.ScaleX = mincale;
if (ct.ScaleY < mincale)
ct.ScaleY = mincale;
//drag whitle zooming.
ct.TranslateX += e.Delta.Translation.X;
ct.TranslateY += e.Delta.Translation.Y;
//checking drag not passed over a screen.that's fails.
if (ct.TranslateX < 10 - img.ActualWidth * ct.ScaleX)
ct.TranslateX = 10 - img.ActualWidth * ct.ScaleX;
if (ct.TranslateX > container.ActualWidth - 10)
ct.TranslateX = container.ActualWidth - 10;
if (ct.TranslateY < 10 - img.ActualHeight * ct.ScaleY)
ct.TranslateY = 10 - img.ActualHeight * ct.ScaleY;
if (ct.TranslateY > container.ActualHeight - 10)
ct.TranslateY = container.ActualHeight - 10;
}
回答1:
you can check for which resolution is there , according to set Image height and width.
var scalfactor = App.Current.Host.Content.ScaleFactor;
switch (scalfactor)
{
case 150:
//write code for 720p or other screen Resolution
break;
case 160:
//write code for Wxga screen Resolution
break;
case 100:
//write code for Wvga screen Resolution
break;
default:
throw new InvalidOperationException("Unknown resolution type");
}
Plz refer this link for more info http://msdn.microsoft.com/en-us/library/windows/apps/jj206974%28v=vs.105%29.aspx
来源:https://stackoverflow.com/questions/26458205/how-to-help-move-the-image-does-not-exceed-the-limit-on-screens