Make control invisible when it goes beyond the parent control? in WPF

I am trying to add a larger MediaElement to a smaller Canvas in WPF.

Suppose I put 600x400 media in a 400x300 canvas with Canvas.Top = -50, Canvas.Left = -100 .

And I do not want the displayed sides not to be displayed, in this case 50 pixels above and below, 100 pixels to the right and left of my media should be invisible.

How can i achieve this? Thanks for the help!

+4
source share
1 answer

What you ask for is called "Clipping". You need to add the RectangleGeometry property to the Canvas.Clip property: -

  <Canvas Width="400" Height="300"> <Canvas.Clip> <RectangleGeometry Rect="0 0 400 300" /> </Canvas.Clip> <!-- Your content here ---> </Canvas> 
+4
source

All Articles