2010-10-26 59 views

回答

7

只是試試這個

// Get a reference to the Button. 
Button myButton = new Button(); 

// Initialize a new DropShadowBitmapEffect that will be applied 
// to the Button. 
DropShadowBitmapEffect myDropShadowEffect = new DropShadowBitmapEffect(); 
// Set the color of the shadow to Black. 
Color myShadowColor = new Color(); 
myShadowColor.ScA = 1; 
myShadowColor.ScB = 0; 
myShadowColor.ScG = 0; 
myShadowColor.ScR = 0; 
myDropShadowEffect.Color = myShadowColor; 

// Set the direction of where the shadow is cast to 320 degrees. 
myDropShadowEffect.Direction = 320; 

// Set the depth of the shadow being cast. 
myDropShadowEffect.ShadowDepth = 25; 

// Set the shadow softness to the maximum (range of 0-1). 
myDropShadowEffect.Softness = 1; 
// Set the shadow opacity to half opaque or in other words - half transparent. 
// The range is 0-1. 
myDropShadowEffect.Opacity = 0.5; 

// Apply the bitmap effect to the Button. 
myButton.BitmapEffect = myDropShadowEffect; 
43

接受的答案是現在已經過時。現在,你可以使用:

UIElement uie = ... 
uie.Effect = 
    new DropShadowEffect 
    { 
     Color = new Color {A = 255, R = 255, G = 255, B = 0}, 
     Direction = 320, 
     ShadowDepth = 0, 
     Opacity = 1 
    }; 

爲了實現作爲接受的答案完全一樣的效果。

+0

不錯,作品完美,謝謝。 – 2012-01-25 15:04:09

+3

工程。請注意,它需要:使用System.Windows.Media.Effects; – Eternal21 2014-10-15 12:13:07

6

@ Gleno的回答對我的幫助最大。在我的情況下,我使用它來對錯過的表單項目進行視覺反饋。然後刪除我使用的dropshadow:

myComboBox.ClearValue(EffectProperty); 

in一個selectionChanged事件。

希望這可以幫助別人。我不得不尋找一點。