Dégradé de couleur en code behind
Bonjour à tous,
comme je le dis dans le titre, je souhaiterais faire un dégradé de couleur comme ça :
Code:
1 2 3 4 5 6 7 8 9
|
<Ellipse Height="50" Width="50">
<Ellipse.Fill>
<RadialGradientBrush Center="0.5,0.5" RadiusX="0.6" RadiusY="0.6">
<GradientStop Color="Red" Offset="0" />
<GradientStop Color="Black" Offset="1"/>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse> |
Mais en code c.net. J'ai essayé de faire ça :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
Style newStyle = new System.Windows.Style();
newStyle.SetValue(RadialGradientBrush.CenterProperty, "0.5,0.5");
newStyle.SetValue(RadialGradientBrush.RadiusXProperty, "0.6");
newStyle.SetValue(RadialGradientBrush.RadiusYProperty, "0.6");
newStyle.SetValue(GradientStop.ColorProperty, Colors.Red);
newStyle.SetValue(GradientStop.OffsetProperty, "0");
newStyle.SetValue(GradientStop.ColorProperty, Colors.Black);
newStyle.SetValue(GradientStop.OffsetProperty, "1");
Rond.Style = newStyle; |
ou :
Code:
1 2 3 4 5 6 7 8 9
|
Rond.Fill.SetValue(RadialGradientBrush.CenterProperty, "0.5,0.5");
Rond.Fill.SetValue(RadialGradientBrush.RadiusXProperty, "0.6");
Rond.Fill.SetValue(RadialGradientBrush.RadiusYProperty, "0.6");
Rond.Fill.SetValue(GradientStop.ColorProperty, Colors.Red);
Rond.Fill.SetValue(GradientStop.OffsetProperty, "0");
Rond.Fill.SetValue(GradientStop.ColorProperty, Colors.Black);
Rond.Fill.SetValue(GradientStop.OffsetProperty, "1"); |
Mais ça ne fonctionne pas!! Quelqu'un pourrait me dire où est l'erreur ou si je suis complétement dans la mauvaise voie??
Merci