c# – WPF:从代码隐藏中为一个元素添加一个dropshadow效果

前端之家收集整理的这篇文章主要介绍了c# – WPF:从代码隐藏中为一个元素添加一个dropshadow效果前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我以为这会很简单,但到目前为止我没有发现任何事情.你怎么做呢?

解决方法

只是试试这个
  1. // Get a reference to the Button.
  2. Button myButton = new Button();
  3.  
  4. // Initialize a new DropShadowBitmapEffect that will be applied
  5. // to the Button.
  6. DropShadowBitmapEffect myDropShadowEffect = new DropShadowBitmapEffect();
  7. // Set the color of the shadow to Black.
  8. Color myShadowColor = new Color();
  9. myShadowColor.ScA = 1;
  10. myShadowColor.ScB = 0;
  11. myShadowColor.ScG = 0;
  12. myShadowColor.ScR = 0;
  13. myDropShadowEffect.Color = myShadowColor;
  14.  
  15. // Set the direction of where the shadow is cast to 320 degrees.
  16. myDropShadowEffect.Direction = 320;
  17.  
  18. // Set the depth of the shadow being cast.
  19. myDropShadowEffect.ShadowDepth = 25;
  20.  
  21. // Set the shadow softness to the maximum (range of 0-1).
  22. myDropShadowEffect.Softness = 1;
  23. // Set the shadow opacity to half opaque or in other words - half transparent.
  24. // The range is 0-1.
  25. myDropShadowEffect.Opacity = 0.5;
  26.  
  27. // Apply the bitmap effect to the Button.
  28. myButton.BitmapEffect = myDropShadowEffect;

猜你在找的C#相关文章