1
我正在Silverlight中做一個圖像畫布(使用Image
和標記)的平移,如下所示。平移正在工作,但圖像在相鄰網格單元中的其他控件的下邊緣和右邊緣處超出外邊界。我無法弄清楚原因。任何建議都會非常有幫助。圖像的平移超出了容器區域
<Border Grid.Row="1" Grid.Column="0">
<Grid HorizontalAlignment="Stretch" Name="gridMain" VerticalAlignment="Stretch">
<Border Name="borderImage" BorderBrush="Black" BorderThickness="1" Height="Auto" Width="Auto" HorizontalAlignment="Left" VerticalAlignment="Top" >
<StackPanel Name="spCanvasHolder" Grid.Row="0" Grid.Column="0" Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Top">
<Canvas Name="canvasImage" Background="Transparent" Width="Auto" MouseWheel="canvasImage_MouseWheel" >
<Image Canvas.Left="0" Canvas.Top="0" Height="Auto" Name="imgMain" Stretch="None" Width="Auto" HorizontalAlignment="Left" VerticalAlignment="Top" MouseLeftButtonDown="imgMain_MouseLeftButtonDown" MouseMove="imgMain_MouseMove" MouseLeftButtonUp="imgMain_MouseLeftButtonUp"/>
</Canvas>
</StackPanel>
</Border>
.
.
</Grid>
</Border>
private void imgMain_MouseMove(object sender, MouseEventArgs e)
{
if (isLeftClicked && isPanningEnabled)
{
....
Thickness currMargin = canvasImage.Margin;
currMargin.Left += lLateralMove;
currMargin.Top += lVerticalMove;
canvasImage.Margin = currMargin;
}
}
會嘗試。不知道它是如何自動夾在頂部和左側的。它只是走出了右邊和底部的界限。 – devnull