2009-10-15 386 views
1

有沒有辦法讓StackPanel中的第一個控件的陰影出現在第二個控件的頂部? 我遇到了麻煩,看圖片!
alt text http://img2.imageshack.us/img2/7073/issuef.png
代碼示例:
StackPanel控件上的WPF陰影

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:sys="clr-namespace:System;assembly=mscorlib"> 
     <Grid> 
     <StackPanel> 
      <Border Height="100" Width="100" Background="Red"> 
       <Border.BitmapEffect> 
        <DropShadowBitmapEffect Color="Black" Direction="270" ShadowDepth="3" Opacity="1" Softness="2" /> 
       </Border.BitmapEffect> 
      </Border> 
       <Border Height="100" Width="100" Background="blue"> 
       </Border> 
      </StackPanel> 
     </Grid> 
    </Page> 

回答

3

你可以在每個邊界的使用Panel.ZIndex="0"直接從XAML設置的項目的z順序。

<StackPanel> 
    <Border Height="100" Width="100" Background="Red" Panel.ZIndex="1"> 
     <Border.BitmapEffect> 
      <DropShadowBitmapEffect Color="Black" Direction="270" ShadowDepth="3" Opacity="1" Softness="2" /> 
     </Border.BitmapEffect> 
    </Border> 
    <Border Height="100" Width="100" Background="blue" Panel.ZIndex="0"> 
    </Border> 
</StackPanel> 

或者你可以使用StackPanel.SetZIndex(object, value)如果你想從代碼做到這一點。