Như tấm hình này: Nói rõ hơn là khi mình zoom thì hình sẽ to hơn và tất nhiên 1 phần trong hình sẽ không thấy được, mình dùng tranlatex,y để drag hình sang trái phải trên dưới nhưng khi kéo nó lại vượt qua with,heigh của màn hình. Bạn nào có cách nào giúp mình... Mình đang lập trình trên windows phone 8.1 runtime.
Để tiện cho việc tìm hiểu và sửa giúp mình, bên dưới đây là code của mình.
Mã:
<Canvas Name="zoomgrid" Visibility="Collapsed">
<Image x:Name="zoomimages"
Stretch="Fill"
Width="480"
Height="800"
ManipulationDelta="img_intro_ManipulationDelta"
RenderTransformOrigin="0.5,0.5"
ManipulationMode="All">
<Image.RenderTransform>
<CompositeTransform/>
</Image.RenderTransform>
</Image>
<Image x:Name="exitimages"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Width="17"
Height="17"
Source="/Assets/cancel-32.png"
Tapped="exitimages_Tapped"
>
<Image.RenderTransform>
<CompositeTransform/>
</Image.RenderTransform>
</Image>
</Canvas>
Mã:
private void img_intro_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
try
{
Image img = sender as Image;
CompositeTransform ct = img.RenderTransform as CompositeTransform;
if (ct == null) return;
ct.ScaleX *= e.Delta.Scale;
ct.ScaleY *= e.Delta.Scale;
if (ct.ScaleX < mincale) ct.ScaleX = mincale;
if (ct.ScaleY < mincale) ct.ScaleY = mincale;
//drag
ct.TranslateX += e.Delta.Translation.X;
ct.TranslateY += e.Delta.Translation.Y;
double scalewidth = zoomimages.ActualWidth * ct.ScaleX;
double scleheight = zoomimages.ActualHeight * ct.ScaleY;
double xdiff = Math.Max(0, (scalewidth - this.lst_intro.ActualWidth) / 2);
double ydiff = Math.Max(0, (scleheight - this.lst_intro.ActualHeight) / 2);
if (Math.Abs(ct.TranslateX) > xdiff)
ct.TranslateX = xdiff * Math.Sign(e.Delta.Translation.X);
if (Math.Abs(ct.TranslateY) > ydiff)
ct.TranslateY = ydiff * Math.Sign(e.Delta.Translation.Y);
}
catch(Exception)
{
return;
}
}
Đây là ví dụ mẫu link này của msdn microsoft.
https://code.msdn.microsoft.com/Zoom...sing-4860ac3c.
View more random threads:
Thông qua phân tích dữ liệu Google từ 86 quốc gia, mới đây, một công ty tại Anh đã công bố bảng xếp hạng kích tấc "cậu nhỏ" của các nước trên thế giới. Kết quả, hầu hết các nước xếp ở nhóm đầu của...
"Chim" của chàng trai Việt thuộc...