2015-10-09 81 views
0

我想在窗體中使用畫布,並縮放和平移那個畫布,首先我把元素主機,然後把畫布放在裏面,然後把畫框放在畫布上,然後試圖放大帆布我嘗試了各種方法,但不執行任何控制的情況下我也寫所有的鼠標滾輪事件,但沒有人執行,所以請給我建議的解決方案下面是我添加控件和鼠標滾輪事件代碼鼠標滾輪事件沒有得到執行

  elementHost1.Height = picVarify.Height; 
     elementHost1.Width = picVarify.Width; 
     elementHost1.Location = picVarify.Location; 
     touchcanvas = new System.Windows.Controls.Canvas(); 
     WindowsFormsHost hst = new WindowsFormsHost(); 
     hst.Name = "Host"; 
     hst.Child = picVarify; 
     hst.Height = picVarify.Height; 
     hst.Width = picVarify.Width; 
     touchcanvas.Height = picVarify.Height; 
     touchcanvas.Width = picVarify.Width; 
     touchcanvas.Children.Add(hst); 
     zm = new ZoomAndPan.ZoomAndPanControl(); 
     zm.Name = "zm"; 
     zm.Content = touchcanvas; 
     zm.MouseWheel += new System.Windows.Input.MouseWheelEventHandler(zoomAndPanControl_MouseWheel); 
     elementHost1.Child = zm; 
     touchcanvas.MouseWheel += new System.Windows.Input.MouseWheelEventHandler(touchcanvas_MouseWheel); 
     hst.MouseWheel += new System.Windows.Input.MouseWheelEventHandler(hst_MouseWheel); 
     picVarify.MouseWheel += new MouseEventHandler(picverify_MouseWheel); 
+1

用於在畫布上,你將不得不設置其背景屬性試試這個背景= Brushes.Transparent射擊鼠標滾輪事件;並讓我知道它是否工作? –

+0

仍然沒有開火 – user3269550

回答

0

這裏的代碼對我來說工作得很好。我在畫布中添加了畫布並設置了兩個畫布的背景屬性。

XAML

<Window x:Class="WpfStack.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525"> 
<Grid x:Name="rootGrid" Margin="10,0,0.4,3.8"> 
    <Canvas Name="BaseCanvas" Background="AliceBlue" Margin="10,0,0,10"> 

    </Canvas> 
</Grid> 

代碼

 public MainWindow() 
     { 
      InitializeComponent(); 
      Canvas touchcanvas = new System.Windows.Controls.Canvas(); 
      touchcanvas.Height =100; 
      touchcanvas.Width = 100; 
      touchcanvas.Background = Brushes.Transparent; 
      touchcanvas.MouseWheel += new System.Windows.Input.MouseWheelEventHandler(touchcanvas_MouseWheel); 
      BaseCanvas.Children.Add(touchcanvas); 
      BaseCanvas.Background = Brushes.Transparent; 

     } 

    public void touchcanvas_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs args) 
     { 
      args.Handled = true; 

     }