Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm working on a game using 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, i.e:

control.left > panel.width

it disappears. Can this be possible in silverlight?

thanks..

like image 339
Hamzeh Soboh Avatar asked Apr 20 '12 11:04

Hamzeh Soboh


1 Answers

You should use the Clip property.

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:

<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>
like image 139
Pedro Lamas Avatar answered Nov 03 '22 01:11

Pedro Lamas