Programming with .NET - Generalhttp://forums.silverlight.net//17.aspx/1?Programming+with+NET+GeneralGeneral discussions around authoring Silverlight .NET applications.Mon, 01 Jan 0001 00:00:00 -0500171892http://forums.silverlight.net//p/908/1892.aspx/1?c+clip+propertyc# clip property <p>Hi. I tried to clip an image when not in fullscreen, and display full image when in fullscreen.</p> <p>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. </p> <p>Now this generates an exception.</p> <p>How to clip the image from c# properly?</p> <p>Thank you in advance</p> 2007-05-09T11:25:37-04:001897http://forums.silverlight.net//p/908/1897.aspx/1?Re+c+clip+propertyRe: c# clip property <p>Something like this works for me...</p> <font size="2"></font><font color="#2b91af" size="2">Canvas</font><font size="2"> c = ir.FindName(</font><font color="#a31515" size="2">&quot;canvas&quot;</font><font size="2">) </font><font color="#0000ff" size="2">as</font><font size="2"> </font><font color="#2b91af" size="2">Canvas</font><font size="2">;</font><font size="2"> <p></font><font color="#2b91af" size="2">RectangleGeometry</font><font size="2"> rg = </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#2b91af" size="2">RectangleGeometry</font><font size="2">();</p> rg.Rect = </font><font color="#0000ff" size="2">new</font><font size="2"> </font> <font color="#2b91af" size="2">Rect</font><font size="2">(0, 0, 48,48);</font><font size="2"> <p>c.Clip = rg;</p> <p>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.</p> </font> 2007-05-09T12:21:23-04:0051970http://forums.silverlight.net//p/908/51970.aspx/1?Re+c+clip+propertyRe: c# clip property <p></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RectangleGeometry xRect = new RectangleGeometry();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xRect.Rect = new Rect(100, 100, 100, 100);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xRect.RadiusX = 20;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xRect.RadiusY = 20;<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Image xImage = new Image();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xImage.Source = new BitmapImage(new Uri(&quot;1.jpg&quot;, UriKind.Relative));<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xImage.Stretch = Stretch.Fill;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xImage.Width = 300;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xImage.Height = 200;<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>xImage.Clip = xRect;<br> </b><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LayoutRoot.Children.Add(xImage);<br> <br> This one works for images<br> </p> 2008-05-08T13:15:03-04:00