0

enter image description here

I try to resize the drop shadow effect in WPF. But I did not find any answer.

  • 1
    Why? The second image is *physically correct* shadow. On the first page the shadow should go much more to the bottom and to the right, it's controlled by [ShadowDepth](https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.effects.dropshadoweffect.shadowdepth) property. – Sinatr Jul 28 '20 at 13:02
  • I think you should provide more information. The figure on the right is a conventional drop shadow. That on the left is not. Just putting an offset black rectangle behind the whatever the blue rectangle is, seems an obvious answer but might not satisfy the requirement. – Andy Jul 28 '20 at 14:59

2 Answers2

3

You cannot set margin to your shadow, so you could "hide" another simple

Border behind your "real" Border.

Wrap them in a Grid that will hold both of them in the same place.

Set your margin on that Border, and set the shadow effect on it as well.

<Grid>
   <Border Margin="20,20,0,0">
       <Border.Effects>
          <DropShadowEffect />
       </Border.Effects/>
   </Border>
   <Border x:Name="YourOriginalBorder"/>
</Grid>
o_w
  • 581
  • 3
  • 12
  • Try give the DropShadowEffect some other parameters, make the shadow bigger, maybe something is hiding/cutting/obstructing it? – o_w Jul 29 '20 at 13:40
  • Thank you brother. You solved my problem. But I have one last question that in this menu there two different border so, Which execute first? I just copy the border and paste in a same it works because I have to set the Content presenter perfectly. But I did not understand how this wrap mechanism works? Can you explain. – MERUN KUMAR MAITY Jul 31 '20 at 20:27
  • The 2 Borders are sitting one on top of the other. The Grid can have columns and rows, and in each "cell" many controls can sit. So in this answer I put 2 controls in the same cell, having the "real" border hiding the "dummy" border that is there only to show a shadow. – o_w Aug 02 '20 at 07:10
1

Just add the Background property to the Border in the o_w's example to show the shadow, or use other controls as example, such as button.

<Grid>
    <Button Content="Button1" Width="150" Height="30">
        <Button.Effect>
            <DropShadowEffect BlurRadius="1" Color="Red" Direction="340" Opacity="10" ShadowDepth="30" RenderingBias="Quality" />
        </Button.Effect>
    </Button>
    <Button Content="Button1" Width="200" Height="40" />
</Grid>

enter image description here

I wanted to post a comment, but I just joined StackOverflow and I can’t do it yet :(.

TimonYang
  • 199
  • 1
  • 8
  • Actually I want this in a control template. I want to apply this on a tool tip which is customized by my control template. The main problem is the width of the border which is {Templatebinding Width}? Can I chat with you I need your help. – MERUN KUMAR MAITY Jul 30 '20 at 20:14