简体   繁体   English

如何在WP7中的画布外面隐藏控件?

[英]How to hide controls when it gets outside a canvas in WP7?

I'm working on a game using WP7 silverlight. 我正在使用WP7 silverlight进行游戏。 Some controls are moving and at some point they get outside the canvas they where in. 一些控件正在移动,并且在某些时候它们会进入它们所在的画布之外。

I wonder why they are not hidden? 我想知道他们为什么不隐藏?

In windows forms when a control gets outside a panel for example, ie: 在窗体中,当控件进入面板时,例如:

control.left > panel.width

it disappears. 它消失了。 Can this be possible in silverlight? Silverlight可以实现吗?

thanks.. 谢谢..

You should use the Clip property. 您应该使用Clip属性。

The following will show a Button that will show outside of the Canvas because button width > canvas width: 以下将显示一个将显示在画布外部的按钮,因为按钮宽度>画布宽度:

<Canvas Width="200" Height="200">
    <Button>My button with a lot of text</Button>
</Canvas>

Now if I add the Clip property, what goes outside of the clip region gets hidden: 现在,如果我添加Clip属性,那么剪辑区域之外的内容将被隐藏:

<Canvas Width="200" Height="200">
    <Canvas.Clip>
        <RectangleGeometry Rect="0,0,200,200" />
    </Canvas.Clip>

    <Button>My button with a lot of text</Button>
</Canvas>

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

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