2016-06-21 49 views
0

我使用下面的代碼拖動&將圖像拖放到畫布上並藉助於縮放縮放,我可以通過觸摸來縮放標籤上的圖像。但我想借助鼠標在桌面上做同樣的事情。可能嗎。我是UWP編程新手,請幫助我。Zoom_In&Zoom_Out在UWP中使用鼠標在畫布上顯示圖像Appliction

      void Drag_ManipulationDelta1(object sender, ManipulationDeltaRoutedEventArgs e) 
    { 
     // Move the rectangle. 
     //dragTranslation.X += e.Delta.Translation.X; 
     //dragTranslation.Y += e.Delta.Translation.Y; 
     TextBlock text = sender as TextBlock; 
     CompositeTransform ct1 = text.RenderTransform as CompositeTransform; 
     ct1.ScaleX *= e.Delta.Scale; 
     ct1.ScaleY *= e.Delta.Scale; 

     if (ct1.ScaleX < 1.0) ct1.ScaleX = 1.0; 
     if (ct1.ScaleY < 1.0) ct1.ScaleY = 1.0; 
     if (ct1.ScaleX > 4.0) ct1.ScaleX = 4.0; 
     if (ct1.ScaleY > 4.0) ct1.ScaleY = 4.0; 
     //Checking with canvas boundary so that image wont go behind canvas 
     if ((ct1.TranslateX + e.Delta.Translation.X) <= (my_canvas.ActualWidth - text.ActualWidth) && ct1.TranslateX + e.Delta.Translation.X >= 0) 
      ct1.TranslateX += e.Delta.Translation.X; 
     if ((ct1.TranslateY + e.Delta.Translation.Y) <= (my_canvas.ActualHeight - text.ActualHeight) && ct1.TranslateY + e.Delta.Translation.Y >= 0) 
      ct1.TranslateY += e.Delta.Translation.Y; 
     if ((ct1.TranslateX + e.Delta.Translation.X) <= (my_canvas.ActualWidth - text.MinWidth) && ct1.TranslateX + e.Delta.Translation.X >= 1150) 
      ct1.TranslateX -= e.Delta.Translation.X; 
     if ((ct1.TranslateY + e.Delta.Translation.Y) <= (my_canvas.ActualHeight - text.MinHeight) && ct1.TranslateY + e.Delta.Translation.Y >= 500) 
      ct1.TranslateY -= e.Delta.Translation.Y; 

    } 


       // DRag and drop the images on canvas 
       imageitem.ManipulationMode = ManipulationModes.All; 
       imageitem.ManipulationDelta += Drag_ManipulationDelta; 
       CompositeTransform ct = new CompositeTransform(); 
       imageitem.RenderTransform = ct; 

回答

0

是其可能

添加Doubletapped事件圖像;

bool isZoomed = false; 
     private void image_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e) 
       { 
        Image img = sender as Image; 
        CompositeTransform ct = img.RenderTransform as CompositeTransform; 
        if (!isZoomed) 
        { 

         ct.ScaleX = 4.0; 
         ct.ScaleY = 4.0; 
         isZoomed = true; 
        } 
        else 
        { 
         ct.ScaleX = 1.0; 
         ct.ScaleY =1.0; 
         isZoomed = false; 

        }   
    } 

註冊PointerWheelChanged event,你可以改變scaleTHreshold

double scalevalue = 0.0; 
     double scaleTHreshold = 4.0; 
     private void image_PointerWheelChanged(object sender, PointerRoutedEventArgs e) 
     { 
      Image img = sender as Image; 
      CompositeTransform ct = img.RenderTransform as CompositeTransform; 
      if (!isZoomed && scalevalue<=scaleTHreshold) 
      { 

       ct.ScaleX = ++scalevalue; 
       ct.ScaleY = scalevalue; 
       if(scalevalue==scaleTHreshold) 
       isZoomed = true; 
      } 
      else 
      { 
       if (--scalevalue == 0.0) 
       { 
        isZoomed = false; 
        return; 
       } 
       ct.ScaleX = scalevalue; 
       ct.ScaleY = scalevalue; 


      } 
     } 
+0

親愛的先生這本書能解決我的這個我的形象一半的問題是縮小而不是放大項。 –

+0

是否可以在鼠標滾輪上縮小和放大圖像 –

+0

是的。我會更新答案 – Archana