我正在使用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;
}
}
答案 0 :(得分:1)
您需要应用裁剪来阻止渲染渲染在控件边界之外。看看UIElement.ClipToBounds is in WPF but not Silverlight. How to simulate in Silverlight?