2013-12-11 51 views
2

比如我有2個Grid S,這樣的:使用負邊距時顯示控件內部的內容。

<Grid Height="200" Width="200" Background="Red"> 
    <Grid HorizontalAlignment="Left" Height="100" Width="100" Background="Blue" Margin="-30,0,0,0" /> 
</Grid> 

而且結果如下:

enter image description here

我怎樣才能創建內容使用負保證金時將只顯示內部控制?
像這樣:

enter image description here

回答

3

您可以使用ClipToBounds =「真「對於網格或其他元素的容器。

<Grid> 
    <Grid Height="200" Width="200" Background="Red" ClipToBounds="True"> 
     <Grid HorizontalAlignment="Left" Height="100" Width="100" Background="Blue" Margin="-30,0,0,0" /> 
    </Grid> 
    </Grid>