1

I need to "hide" a few pixels of a given image. In HTML / CSS i would do something like this to hide 10 pixels from the left:

<div id="test" style="overflow: hidden;">
  <img style="margin-left: -10px;" src="some.png">
</div>

Is there any way to achieve the same result in Silverlight, using Grid and Image Control?

user3428756
  • 87
  • 2
  • 5
  • possible duplicate of [How does Silverlight Image Clipping work?](http://stackoverflow.com/questions/745541/how-does-silverlight-image-clipping-work) – Martin Liversage Mar 17 '14 at 12:44
  • The problem i see with clipping is that i need to know the exact dimensions of the image to be able to position the clipping geometry. Using the overflow:hidden technique above, i'm able to hide 10pxs of the image no matter how small or large the image might be – user3428756 Mar 17 '14 at 13:05
  • Probably the `Clip` proeprty will do this: http://stackoverflow.com/questions/1226777/silverlight-canvas-overflows – vortexwolf Mar 17 '14 at 16:32

1 Answers1

0

There's multiple ways of accomplishing this;

You can do like they're saying with Clip

<Rectangle Height="200" Width="200" Fill="Red">
   <Rectangle.Clip>
      <RectangleGeometry Rect="10,0,200,200"/>
   </Rectangle.Clip>
</Rectangle>

Except the problem with that is (like you pointed out) is it's dependent on knowing the dimensions and isn't very intuitive. There's ways using code behind to specify a way of having more active control over your Rect Geometry like shown here or here.

However there's also ways around that which is kind of cheating, like using a panel type that will do it for you like ScrollViewer

<ScrollViewer Width="100" Height="100" Padding="0" 
              HorizontalScrollBarVisibility="Disabled" 
              VerticalScrollBarVisibility="Disabled">
   <Rectangle Fill="Red" Margin="-10,0,0,0"/>
</ScrollViewer>

Cool thing about any XAML is, if there's a will, then there's usually a way. Hope this helps.

Community
  • 1
  • 1
Chris W.
  • 22,835
  • 3
  • 60
  • 94