Set a Clip in Code-Behind

You can use the Clip property on any item to clip its display area. For example if you have this two items rectBlue and rectRed like this

image

And you want to animate rectRed by sliding it out from the right side, without clipping it would look like this

image

But if you set the Clip property on the blue rectangle to equal its dimension then it would look like this

image

You can set the clip in code-behind like this:

RectangleGeometry recClip =  new RectangleGeometry();
recClip.Rect = new Rect(0, 0, recBlue.ActualWidth, recBlue.ActualHeight);
pnlContent.Clip = recClip;

This works in both Silverlight and WPF.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s