Dynamic Silverlight Clipping Masks

Here’s a quick way to set a dynamic clipping mask in Silverlight. Quite proud of this.

The .Clip property is common to lots of objects so this can be adapted to Canvases or Button, etc.

public void SetDynamicClipRect(FrameworkElement Sender, String ObjectToClip)
Grid c = Sender.FindName(ObjectToClip) as Grid;

Double aw = c.ActualWidth;
Double ah = c.ActualHeight;

RectangleGeometry rg = new RectangleGeometry();
rg.Rect = new Rect(0, 0, aw, ah);

c.Clip = rg;
  1. No trackbacks yet.

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: