<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Silverlight ClipToBounds &#8211; Can I Clip It?, Yes You Can!</title>
	<atom:link href="http://www.scottlogic.co.uk/blog/colin/2009/05/silverlight-cliptobounds-can-i-clip-it-yes-you-can/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scottlogic.co.uk/blog/colin/2009/05/silverlight-cliptobounds-can-i-clip-it-yes-you-can/</link>
	<description>Colin Eberhardt&#039;s Adventures in WPF</description>
	<lastBuildDate>Tue, 09 Mar 2010 08:51:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Colin Eberhardt</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/05/silverlight-cliptobounds-can-i-clip-it-yes-you-can/comment-page-1/#comment-8970</link>
		<dc:creator>Colin Eberhardt</dc:creator>
		<pubDate>Wed, 03 Mar 2010 14:37:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=292#comment-8970</guid>
		<description>Hi Ian,

I am happy for you to make commercial use of this class, as long as you link to this blog in some way.

Glad you liked the subtle reference ;-)

Colin E.</description>
		<content:encoded><![CDATA[<p>Hi Ian,</p>
<p>I am happy for you to make commercial use of this class, as long as you link to this blog in some way.</p>
<p>Glad you liked the subtle reference <img src='http://www.scottlogic.co.uk/blog/colin/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Colin E.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/05/silverlight-cliptobounds-can-i-clip-it-yes-you-can/comment-page-1/#comment-8969</link>
		<dc:creator>Ian</dc:creator>
		<pubDate>Wed, 03 Mar 2010 14:29:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=292#comment-8969</guid>
		<description>Hey Colin,

I am wondering what the policy is regarding using your Clip class within a commercial project? It was exactly what I needed to get my project working as I wanted.

Currently I have the class included in my project and I added the URL to your blog (this page) in the comments section.

Thanks,

Ian

PS: I would also like to acknowledge the awesomeness of including Tribe lyrics. Very nice.</description>
		<content:encoded><![CDATA[<p>Hey Colin,</p>
<p>I am wondering what the policy is regarding using your Clip class within a commercial project? It was exactly what I needed to get my project working as I wanted.</p>
<p>Currently I have the class included in my project and I added the URL to your blog (this page) in the comments section.</p>
<p>Thanks,</p>
<p>Ian</p>
<p>PS: I would also like to acknowledge the awesomeness of including Tribe lyrics. Very nice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rana</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/05/silverlight-cliptobounds-can-i-clip-it-yes-you-can/comment-page-1/#comment-8927</link>
		<dc:creator>rana</dc:creator>
		<pubDate>Tue, 02 Mar 2010 03:17:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=292#comment-8927</guid>
		<description>Thanks.
That helped a lot.</description>
		<content:encoded><![CDATA[<p>Thanks.<br />
That helped a lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/05/silverlight-cliptobounds-can-i-clip-it-yes-you-can/comment-page-1/#comment-8026</link>
		<dc:creator>Stephen</dc:creator>
		<pubDate>Mon, 01 Feb 2010 22:49:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=292#comment-8026</guid>
		<description>Thank you! I took your basic code and adjusted it so it isn&#039;t just a &quot;clip to bounds&quot; but a &quot;clip to relative bounds&quot;. Instead of a boolean, you can set a Rect, but you set it in terms of relative positions, so 0,0,1,1 is the full bounds. 0,0.5,0.5,0.5 would show just the lower left quadrant. 

Since I got the basic code from you, I figure it&#039;s only fair to share my modification back with you and the rest of the community. 

    /// 
    /// This class provides a way for controls to set a rectangular clip region that scales with them. This class
    /// gives an easy way to specify relative clip geometry so you can have a control that renders outside of its 
    /// bounds still be clipped down to those bounds without having to specify a fixed width and height.
    /// 
    /// 
    /// To use this class, set the RelativeRectangleClip.ToRect property on a FrameworkElement. The rectangle
    /// should use relative positions and relative height/width.
    /// A value of &quot;0,0,1,1&quot; will set a clip rectangle of the full actual bounds of the FrameworkElement.
    /// Setting this property overrides any assignment of the element&#039;s own Clip property.
    /// 
    public class RelativeRectangleClip
    {
        /// 
        /// Gets the rectangle that will be used to create the clip geometry for the given object.
        /// 
        /// The object
        /// The current relative clip rectangle
        public static Rect GetToRect(DependencyObject depObj)
        {
            return (Rect)depObj.GetValue(ToRectProperty);
        }

        /// 
        /// Sets the rectangle that will be used to create the clip geometry for the given object. Positions
        /// and sizes should be relative values. Actual values will be calculated when the object is measured
        /// and arranged.
        /// 
        /// The object
        /// The desired relative clip rectangle
        public static void SetToRect(DependencyObject depObj, Rect clipToRect)
        {
            depObj.SetValue(ToRectProperty, clipToRect);
        }

        /// 
        /// Identifies the ToRect Dependency Property.
        /// 
        public static readonly DependencyProperty ToRectProperty =
            DependencyProperty.RegisterAttached(&quot;ToRect&quot;, typeof(Rect),
            typeof(RelativeRectangleClip), new PropertyMetadata(OnToRectPropertyChanged));

        private static void OnToRectPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            FrameworkElement fe = d as FrameworkElement;
            if (fe != null)
            {
                ClipToRect(fe);

                // whenever the element which this property is attached to is loaded
                // or re-sizes, we need to update its clipping geometry
                fe.Loaded += new RoutedEventHandler(fe_Loaded);
                fe.SizeChanged += new SizeChangedEventHandler(fe_SizeChanged);

            }
        }

        /// 
        /// Creates a rectangular clipping geometry which matches the geometry of the
        /// passed element, using relative positioning of the rect based on the ToRect property.
        /// 
        private static void ClipToRect(FrameworkElement fe)
        {
            Rect clip = GetToRect(fe);
            if ((clip.Height != 0) &#124;&#124; (clip.Width != 0))
            {
                fe.Clip = new RectangleGeometry()
                {
                    Rect = new Rect(fe.ActualWidth * clip.Left, fe.ActualHeight * clip.Top, fe.ActualWidth * clip.Width, fe.ActualHeight * clip.Height)
                };
            }
            else
            {
                fe.Clip = null;
            }
        }

        static void fe_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            ClipToRect(sender as FrameworkElement);
        }

        static void fe_Loaded(object sender, RoutedEventArgs e)
        {
            ClipToRect(sender as FrameworkElement);
        }
    }</description>
		<content:encoded><![CDATA[<p>Thank you! I took your basic code and adjusted it so it isn&#8217;t just a &#8220;clip to bounds&#8221; but a &#8220;clip to relative bounds&#8221;. Instead of a boolean, you can set a Rect, but you set it in terms of relative positions, so 0,0,1,1 is the full bounds. 0,0.5,0.5,0.5 would show just the lower left quadrant. </p>
<p>Since I got the basic code from you, I figure it&#8217;s only fair to share my modification back with you and the rest of the community. </p>
<p>    ///<br />
    /// This class provides a way for controls to set a rectangular clip region that scales with them. This class<br />
    /// gives an easy way to specify relative clip geometry so you can have a control that renders outside of its<br />
    /// bounds still be clipped down to those bounds without having to specify a fixed width and height.<br />
    ///<br />
    ///<br />
    /// To use this class, set the RelativeRectangleClip.ToRect property on a FrameworkElement. The rectangle<br />
    /// should use relative positions and relative height/width.<br />
    /// A value of &#8220;0,0,1,1&#8243; will set a clip rectangle of the full actual bounds of the FrameworkElement.<br />
    /// Setting this property overrides any assignment of the element&#8217;s own Clip property.<br />
    ///<br />
    public class RelativeRectangleClip<br />
    {<br />
        ///<br />
        /// Gets the rectangle that will be used to create the clip geometry for the given object.<br />
        ///<br />
        /// The object<br />
        /// The current relative clip rectangle<br />
        public static Rect GetToRect(DependencyObject depObj)<br />
        {<br />
            return (Rect)depObj.GetValue(ToRectProperty);<br />
        }</p>
<p>        ///<br />
        /// Sets the rectangle that will be used to create the clip geometry for the given object. Positions<br />
        /// and sizes should be relative values. Actual values will be calculated when the object is measured<br />
        /// and arranged.<br />
        ///<br />
        /// The object<br />
        /// The desired relative clip rectangle<br />
        public static void SetToRect(DependencyObject depObj, Rect clipToRect)<br />
        {<br />
            depObj.SetValue(ToRectProperty, clipToRect);<br />
        }</p>
<p>        ///<br />
        /// Identifies the ToRect Dependency Property.<br />
        ///<br />
        public static readonly DependencyProperty ToRectProperty =<br />
            DependencyProperty.RegisterAttached(&#8220;ToRect&#8221;, typeof(Rect),<br />
            typeof(RelativeRectangleClip), new PropertyMetadata(OnToRectPropertyChanged));</p>
<p>        private static void OnToRectPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)<br />
        {<br />
            FrameworkElement fe = d as FrameworkElement;<br />
            if (fe != null)<br />
            {<br />
                ClipToRect(fe);</p>
<p>                // whenever the element which this property is attached to is loaded<br />
                // or re-sizes, we need to update its clipping geometry<br />
                fe.Loaded += new RoutedEventHandler(fe_Loaded);<br />
                fe.SizeChanged += new SizeChangedEventHandler(fe_SizeChanged);</p>
<p>            }<br />
        }</p>
<p>        ///<br />
        /// Creates a rectangular clipping geometry which matches the geometry of the<br />
        /// passed element, using relative positioning of the rect based on the ToRect property.<br />
        ///<br />
        private static void ClipToRect(FrameworkElement fe)<br />
        {<br />
            Rect clip = GetToRect(fe);<br />
            if ((clip.Height != 0) || (clip.Width != 0))<br />
            {<br />
                fe.Clip = new RectangleGeometry()<br />
                {<br />
                    Rect = new Rect(fe.ActualWidth * clip.Left, fe.ActualHeight * clip.Top, fe.ActualWidth * clip.Width, fe.ActualHeight * clip.Height)<br />
                };<br />
            }<br />
            else<br />
            {<br />
                fe.Clip = null;<br />
            }<br />
        }</p>
<p>        static void fe_SizeChanged(object sender, SizeChangedEventArgs e)<br />
        {<br />
            ClipToRect(sender as FrameworkElement);<br />
        }</p>
<p>        static void fe_Loaded(object sender, RoutedEventArgs e)<br />
        {<br />
            ClipToRect(sender as FrameworkElement);<br />
        }<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Eberhardt</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/05/silverlight-cliptobounds-can-i-clip-it-yes-you-can/comment-page-1/#comment-6381</link>
		<dc:creator>Colin Eberhardt</dc:creator>
		<pubDate>Mon, 07 Dec 2009 16:18:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=292#comment-6381</guid>
		<description>Finally .... thank you :-)

Regards, Colin E.</description>
		<content:encoded><![CDATA[<p>Finally &#8230;. thank you <img src='http://www.scottlogic.co.uk/blog/colin/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Regards, Colin E.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
