堆栈面板控件上的 WPF 阴影 [英] WPF shadow on stackpanel controls

查看:69
本文介绍了堆栈面板控件上的 WPF 阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 StackPanel 中第一个控件的阴影出现在第二个控件的顶部?我遇到了这个问题,请看图片!
替代文字 http://img2.imageshack.us/img2/7073/issuef.png
代码示例:

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>

推荐答案

您可以在每个 Borders 中使用 Panel.ZIndex="0" 直接从XAML.

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>

或者你可以使用 StackPanel.SetZIndex(object, value) 如果你想从代码中做到这一点.

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

这篇关于堆栈面板控件上的 WPF 阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆