日期:2014-05-17  浏览次数:20926 次

WPF,请看下这个布局

ontalAlignment="Left" Height="504" VerticalAlignment="Top" Width="760">
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <DockPanel>
        <Button Content="button1" Margin="-10" Background="Blue" Panel.ZIndex="1"/>
    </DockPanel>
    <Border BorderBrush="Red" BorderThickness="2" Grid.Row="1" />
</Grid>



上面的Grid中有两行,第一行有个DockPanel,里面放了个Button,第二行是一个Border。设置了Button的Margin值为-10。

问题:
1:为什么Button没有遮住下面Border的上边线?
2:第一行如果取消DockPanel,直接放Button,为什么就能遮住下面Border的上边线?

------解决方案--------------------
ZIndex只负责同一个面板下的元素Z轴顺序调整,而Button和Border不在同一个面板下,你应该给DockPanel设置ZIndex