Je pensais que ce serait quelque chose de simple mais jusqu'à présent je n'ai rien trouvé. Comment faites-vous?WPF: Ajouter un effet dropshadow à un élément de code-behind
9
A
Répondre
7
juste essayer ce
// 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
La réponse acceptée est maintenant obsolète. Maintenant, vous pouvez utiliser:
UIElement uie = ...
uie.Effect =
new DropShadowEffect
{
Color = new Color {A = 255, R = 255, G = 255, B = 0},
Direction = 320,
ShadowDepth = 0,
Opacity = 1
};
Pour obtenir exactement le même effet que la réponse acceptée.
6
@ La réponse de Gleno m'a aidé le plus. Dans mon cas, je l'utilisais pour un retour visuel sur un objet de formulaire manqué. Pour supprimer ensuite le dropshadow j'ai utilisé:
myComboBox.ClearValue(EffectProperty);
dans un événement selectionChanged.
Espérons que cela aide quelqu'un. J'ai dû chercher un peu.
Questions connexes
- 1. WPF DataGrid reliure: Ajouter un nouvel élément
- 2. WPF DataGrid Row ajouter dans codebehind
- 3. Ajouter un MouseOverHandler à un élément?
- 4. Ajouter un élément à un objet jquery
- 5. Comment ajouter un élément à un ListView?
- 6. Ajouter un élément à un tableau
- 7. Ajouter un élément à un tableau
- 8. Ajouter un effet à certaines des lignes dans un DataGrid
- 9. ListBox Dropshadow Animation
- 10. Comment référencer un élément de menu sélectionné dans codebehind?
- 11. WPF pivoter un élément
- 12. Ajouter une image silverlight hovereffect de codebehind
- 13. Ajouter un élément de navigation à un contrôleur de vue
- 14. Y at-il un effet WPF Typewriter?
- 15. débutants onglets jQuery - ajouter un effet assouplissement
- 16. Comment ajouter un attribut à un XML avec un compte de cet élément avec un élément
- 17. Ajouter un effet lumineux au cercle
- 18. Reliure WPF ComboBox à un élément
- 19. Comment ajouter un attribut à un élément de schéma xml?
- 20. Ajouter un élément à une chaîne [] tableau
- 21. Désactiver Ajouter un élément à la collection
- 22. F # Ajouter un élément à une séquence
- 23. Ajouter une classe à un élément
- 24. WPF: ajouter du style à un curseur
- 25. WPF - Comment appliquer un effet à une image recadrée?
- 26. Ajouter une ligne à UITableView pour ajouter un nouvel élément?
- 27. Effet de glissement lors de l'ajout de nouveaux éléments à un ListBox WPF
- 28. WPF: Ajouter un style de bordure à l'image progammatiquement
- 29. ajouter un élément au dictionnaire
- 30. Pattern Repository: Ajouter un élément
Nice, fonctionne parfaitement, merci. –
Fonctionne. Juste une note, il faut: using System.Windows.Media.Effects; – Eternal21