Skip to main content

Microsoft Silverlight

Unanswered Question c# clip propertyRSS Feed

(0)

bituman
bituman

Member

Member

2 points

4 Posts

c# clip property

Hi. I tried to clip an image when not in fullscreen, and display full image when in fullscreen.

I tried setting the clip property, which waits a geometry. I tried creating a custom shape (rectangle) set the width and height, convert it to pathway, and set myImage.Clip = pathwayRectangle.Data; in the c# code.

Now this generates an exception.

How to clip the image from c# properly?

Thank you in advance

Bill Reiss
Bill Reiss

Contributor

Contributor

4840 points

919 Posts

Silverlight MVP

Re: c# clip property

Something like this works for me...

Canvas c = ir.FindName("canvas") as Canvas;

RectangleGeometry rg = new RectangleGeometry();

rg.Rect = new Rect(0, 0, 48,48);

c.Clip = rg;

In my case, the canvas wraps the image, so I'm not sure if you would need to do something similar or clip the image itself.


Bill Reiss, Coauthor of Hello! Silverlight 3
My blog (rss feed)

fatihpiristine
fatihpir...

Member

Member

8 points

4 Posts

Re: c# clip property

            RectangleGeometry xRect = new RectangleGeometry();
            xRect.Rect = new Rect(100, 100, 100, 100);
            xRect.RadiusX = 20;
            xRect.RadiusY = 20;

            Image xImage = new Image();
            xImage.Source = new BitmapImage(new Uri("1.jpg", UriKind.Relative));
            xImage.Stretch = Stretch.Fill;
            xImage.Width = 300;
            xImage.Height = 200;

            xImage.Clip = xRect;

            LayoutRoot.Children.Add(xImage);

This one works for images

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities