WPF shadow on stackpanel controls

有些话、适合烂在心里 提交于 2019-12-12 23:43:36

问题


Is there a way to make the shadow of the first control in a StackPanel appear on top of the second control? I'm having trouble with this, look at the picture!
alt text http://img2.imageshack.us/img2/7073/issuef.png
Code sample:

 <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>

回答1:


You can do use Panel.ZIndex="0" in each of the Borders to set the z order of the items directly from the XAML.

<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>

Or you can use StackPanel.SetZIndex(object, value) if you wanted to do it from code.



来源:https://stackoverflow.com/questions/1571832/wpf-shadow-on-stackpanel-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!