没有“溢出”的阴影

问题描述

我想创建一个只向一个方向移动而不会“起泡”的阴影。

Shadow "spill"

正如您在左侧和右侧看到的那样,阴影是“散落的”,但我希望阴影只是向上而不是向两侧。我怎样才能做到这一点?这是我到目前为止的代码

<UserControl x:Class="Client.Views.CartItemToolBar"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:ctrl="clr-namespace:Client.Controls"
         xmlns:local="clr-namespace:Client.Views"
         mc:Ignorable="d">
<Grid Height="56" Background="{StaticResource color_white}" Margin="2,0">
    <Border Background="Transparent" BorderBrush="{Binding Path=Background,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Grid}}" BorderThickness="0,10,0">
        <Border.Effect>
            <DropShadowEffect ShadowDepth="0" BlurRadius="16" Direction="90" />
        </Border.Effect>
    </Border>
    <StackPanel Orientation="Horizontal" Background="{Binding Path=Background,AncestorType=Grid}}">
        <ctrl:TestButton Style="{StaticResource ButtonCartPositionAction}" PosAction="CartItem/Minus">
            <ctrl:IconViewBox IconData="{StaticResource IconPathNumericNegative1}" IconSize="20" RenderTransformOrigin="0.5,0.5" >
                <ctrl:IconViewBox.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform/>
                        <TranslateTransform X="-4" Y="-4"/>
                    </TransformGroup>
                </ctrl:IconViewBox.RenderTransform>
            </ctrl:IconViewBox>
        </ctrl:TestButton>
        <ctrl:TestButton Style="{StaticResource ButtonCartPositionAction}" PosAction="CartItem/Plus" >
            <ctrl:IconViewBox IconData="{StaticResource IconPathNumericPositive1}" IconSize="20" RenderTransformOrigin="0.5,0.5" >
                <ctrl:IconViewBox.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform/>
                        <TranslateTransform X="-4" Y="-4"/>
                    </TransformGroup>
                </ctrl:IconViewBox.RenderTransform>
            </ctrl:IconViewBox>
        </ctrl:TestButton>
        <ctrl:TestButton Style="{StaticResource ButtonCartPositionAction}" Content="Change Price" PosAction="CartItem/ChangePrice" />
        <ctrl:TestButton Style="{StaticResource ButtonCartPositionAction}" PosAction="UI/SwitchTo/CartItemdiscount">
            <Grid>
                <Label Margin="0" Padding="0">Pos discount</Label>                    
            </Grid>
        </ctrl:TestButton>            
        <ctrl:TestButton Style="{StaticResource ButtonCartPositionAction}" PosAction="CartItem/Remove">
            <ctrl:IconViewBox IconData="{StaticResource IconPathTrashCan}" IconSize="20" />
        </ctrl:TestButton>
    </StackPanel>        
</Grid>

解决方法

感谢克莱门斯的评论,经过一番尝试,我找到了答案。我已经忘记了,如果边距为负,则可以在边界“外部”显示控件。

Shadow from Rectangle

<UserControl x:Class="Client.Views.CartItemToolBar"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:ctrl="clr-namespace:Client.Controls"
     xmlns:local="clr-namespace:Client.Views"
     mc:Ignorable="d">
<Grid Margin="2,0">
    <Rectangle Margin="0,-12,56">
        <Rectangle.Fill>
            <LinearGradientBrush StartPoint="0.5,1" EndPoint="0.5,0">
                <GradientStop Color="#DDDDDD" Offset="0" />
                <GradientStop Color="Transparent" Offset="1" />
            </LinearGradientBrush>
        </Rectangle.Fill>
    </Rectangle>
    <Grid Height="56" Background="{StaticResource color_white}">
        <StackPanel Orientation="Horizontal" Background="{Binding Path=Background,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Grid}}">
            <ctrl:TestButton Style="{StaticResource ButtonCartPositionAction}" PosAction="CartItem/Minus">
                <ctrl:IconViewbox IconData="{StaticResource IconPathNumericNegative1}" IconSize="20" RenderTransformOrigin="0.5,0.5" >
                    <ctrl:IconViewbox.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform X="-4" Y="-4"/>
                        </TransformGroup>
                    </ctrl:IconViewbox.RenderTransform>
                </ctrl:IconViewbox>
            </ctrl:TestButton>
            <ctrl:TestButton Style="{StaticResource ButtonCartPositionAction}" PosAction="CartItem/Plus" >
                <ctrl:IconViewbox IconData="{StaticResource IconPathNumericPositive1}" IconSize="20" RenderTransformOrigin="0.5,0.5" >
                    <ctrl:IconViewbox.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform X="-4" Y="-4"/>
                        </TransformGroup>
                    </ctrl:IconViewbox.RenderTransform>
                </ctrl:IconViewbox>
            </ctrl:TestButton>
            <ctrl:TestButton Style="{StaticResource ButtonCartPositionAction}" Content="Change Price" PosAction="CartItem/ChangePrice" />
            <ctrl:TestButton Style="{StaticResource ButtonCartPositionAction}" PosAction="UI/SwitchTo/CartItemDiscount">
                <Grid>
                    <Label Margin="0" Padding="0">Pos Discount</Label>                    
                </Grid>
            </ctrl:TestButton>            
            <ctrl:TestButton Style="{StaticResource ButtonCartPositionAction}" PosAction="CartItem/Remove">
                <ctrl:IconViewbox IconData="{StaticResource IconPathTrashCan}" IconSize="20" />
            </ctrl:TestButton>
        </StackPanel>        
    </Grid>
</Grid>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...