Reputation: 29208
I am doing panning of an image canvas(with Image
and markings on it) in silverlight as shown below. Panning is working but the image does beyond the outer border in lower and right edges over the other controls in the adjacent grid cells. I could not figure out the reason. Any suggestions would be very helpful.
<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;
}
}
Upvotes: 1
Views: 124
Reputation: 29083
You'll need to apply clipping to stop it from rendering rendering outside the control's bounds. Take a look at UIElement.ClipToBounds is in WPF but not Silverlight. How to simulate in Silverlight?
Upvotes: 1