简体   繁体   English

当控件超出父控件的范围时使控件不可见? 在 WPF

[英]Making a control invisible when its out of bounds of a parent control? in WPF

I'm trying to put a bigger MediaElement into a smaller Canvas on WPF.我正在尝试将更大的MediaElement放入Canvas上的较小的 Canvas 中。

Lets say i'm putting 600x400 media into a 400x300 Canvas with Canvas.Top = -50, Canvas.Left = -100 .假设我将 600x400 媒体放入 400x300 Canvas 中,其中Canvas.Top = -50, Canvas.Left = -100

And i don't want the sides that are out of bounds to be displayed, in this case 50 pixels from top and bottom, 100 pixel from right and left of my media should be invisible.而且我不希望显示超出范围的边,在这种情况下,从顶部和底部 50 像素,从我的媒体的右侧和左侧 100 像素应该是不可见的。

How can i achieve this?我怎样才能做到这一点? Thanks for all the help!感谢所有的帮助!

What you are asking for is called "Clipping".您所要求的称为“剪辑”。 You need to add a RectangleGeometry to the Canvas.Clip property:-您需要将RectangleGeometry添加到Canvas.Clip属性:-

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM