Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

c# clip property RSS

2 replies

Last post May 08, 2008 02:15 PM by fatihpiristine

(0)
  • bituman

    bituman

    Member

    2 Points

    4 Posts

    c# clip property

    May 09, 2007 12:25 PM | LINK

    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

    c# silverlight clip property

  • Bill Reiss

    Bill Reiss

    Contributor

    4973 Points

    947 Posts

    Re: c# clip property

    May 09, 2007 01:21 PM | LINK

    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
    My blog
  • fatihpiristine

    fatihpiristine

    Member

    8 Points

    4 Posts

    Re: c# clip property

    May 08, 2008 02:15 PM | LINK

                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