want to clip a canvas as a mouse is dragged on the edge of it


silverlight code tips 

So this is common request in apps these days.

Here’s the code that someone at silverlight.net forums posted. I’ve copied it here cause it’s a good simple snippet of code

XAML


<Canvas Canvas.Left="0" Canvas.Top="200">
  <Rectangle Width="300" Height="400" Fill="Black" Cursor="Hand" MouseLeftButtonUp="ChangeClip"/>
  <Canvas.Clip >
  <RectangleGeometry x:Name="ClipRect" Rect='0, 0, 300, 400' />
  </Canvas.Clip>
  </Canvas>

Javascript


 function ChangeClip(sender, args)
{
  var clip = sender.findName("ClipRect");
  clip["Rect"]="0, 0, 300, 100";
}

6 responses to “want to clip a canvas as a mouse is dragged on the edge of it

  1. so this is great for clipping a canvas using a rectangle shape. what about irregular shapes, a trapezoid for instance?

    i simply want to mask an animation within a trapezoid frame..any pointers?

  2. You can use PathGeometry for that, and just define the points for the trapezoid.

  3. A goal without action is just like a dead head Do it now or you will be regretful because of missing a valuable chance

  4. I’m curious to find out what blog system you’re utilizing?
    I’m having some small security problems with my latest website and I’d like too fiind something more safeguarded.
    Do youu have any suggestions?

  5. Jangan berpikir kamu tak mampu hidup tanpa dia yg meninggalkanmu. Percaya ada seseorang yg lebih baik menunggumu di luar sana.

  6. Jadi dirimu sendiri agar ketika seseorang mencintai kamu tak perlu takut jika dia akan temukan dirimu bukan orang yang ingin dia cintai

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