<Window x:Class="LayoutPanels.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Canvas Grid.Column="1" ClipToBounds="True">
<Button Canvas.Left="10" Canvas.Top="10">(10,10)</Button>
<Button Canvas.Right="120" Canvas.Top="30" Width="200">(120,30)</Button>
<Button Canvas.Left="60" Canvas.Top="80" Width="50" Height="50">(60,80)</Button>
<Button Canvas.Left="70" Canvas.Top="120" Width="100" Height="50">(70,120)</Button>
</Canvas>
</Grid>
</Window>
提示:如何和其他元素一起使用Canvas面板,可以设置ClipToBounds属性为True。这样,如果Canvas中元素被拉伸超出Canvas面板界面时,就会在Canvas面板边界处剪裁这些的子元素(这样可以阻止它们和窗口中的其他元素重叠)。其他所有布局容器总是剪裁它们的子元素以适应其尺寸,而不考虑ClipToBounds的设置。