2017-10-15 4 views

Répondre

1

Modification de la couleur à C#

Anything.Foreground = (SolidColorBrush)Application.Current.Resources["SystemControlForegroundAccentBrush"]; 

Tout est votre bouton, texte, etc. Tout ce qui le soutiennent

Vous pouvez utiliser Color.FromArgb() pour définir une coutume couleur dans le code:

Anything.Foreground = new SolidColorBrush(Color.FromArgb(255, 225, 48, 221)); 

Il suffit de modifier le code ARVB selon vos besoins

Et Plus si vous voulez un code couleur hexadécimal à l'avenir dans votre application, vous pouvez le faire:

Créer une méthode pour convertir la chaîne Hex pour SolidColorBrush :

public SolidColorBrush GetSolidColorBrush(string hex) 
{ 
    hex = hex.Replace("#", string.Empty); 
    byte a = (byte)(Convert.ToUInt32(hex.Substring(0, 2), 16)); 
    byte r = (byte)(Convert.ToUInt32(hex.Substring(2, 2), 16)); 
    byte g = (byte)(Convert.ToUInt32(hex.Substring(4, 2), 16)); 
    byte b = (byte)(Convert.ToUInt32(hex.Substring(6, 2), 16)); 
    SolidColorBrush myBrush = new SolidColorBrush(Windows.UI.Color.FromArgb(a, r, g, b)); 
    return myBrush; 
} 

maintenant, tout ce qui reste est d'obtenir la couleur en appelant la méthode et passer la chaîne hexagonale pour comme paramètre:

var color = GetSolidColorBrush("#FFDC3569").Color; 
+0

Merci, homme. Très utile – Vincent

+0

:), .............. –