2017-05-23 1 views
-1

J'ai trouvé une grande énumération de la bibliothèque FontAwesome et je veux l'utiliser dans mon application WPF pour les icônes/images dans Textblocks. Le ENUM se présente comme suit:Enum valeur hexadécimale au texte textbloc

public enum Type 
{ 
    ... 
    //ExclamationCircle, 0xf06A 
    ExclamationCircle = 0xf06A, 
    //ExclamationTriangle, 0xf071 
    ExclamationTriangle = 0xf071, 
    //Expand, 0xf065 
    Expand = 0xf065, 
    ... 
} 

Je voudrais utiliser ce ENUM pour définir la valeur de mon Textblock donc je n'ai pas d'utiliser la valeur HEX à côté (0xf071 par exemple). Dans mon XAML, je donne les résultats suivants qui fonctionne comme je veux:

<TextBlock x:Name="tbIcon" FontFamily="{StaticResource FontAwesome}" Text="&#xf071;" Foreground="{StaticResource RedBrush}" FontSize="20" VerticalAlignment="Center" Margin="10" /> 

binding image

Quand j'ajoute le code suivant, je n'obtiens plus l'image mais le texte lui-même, je suis entré.

public DialogBase(string title, string message, Window owner) 
{ 
    InitializeComponent(); 
    tbIcon.Text = FontAwesome.Type.ExclamationTriangle.AsHexString(); 
} 

public static string AsHexString(this FontAwesome.Type type) 
{ 
    return String.Format(@"\u{0}", ((int)type).ToString("X").ToLower()); 
    // This is returning "\uf071" 
} 

incorrect image

À long terme, je veux en faire une propriété publique d'un nouveau contrôle afin qu'il puisse être lié, mais je suis désireux d'obtenir cette étape de travail d'abord.

Répondre

0

Essayez de changer u à x:

public static string AsHexString(this FontAwesome.Type type) 
{ 
    return String.Format(@"\x{0}", ((int)type).ToString("X").ToLower()); 
    // This is returning "\xf071" 
} 

Vous pouvez également essayer de régler le FontFamily comme ceci:

<TextBlock x:Name="tbIcon" TextElement.FontFamily="pack://application:,,,/FontAwesome.WPF;component/#FontAwesome" Foreground="{StaticResource RedBrush}" FontSize="20" VerticalAlignment="Center" Margin="10" /> 

Il fonctionne pour moi :)