Adding text with fontovesome to WPF button

I am trying to create some text under the fontawesome icon inside WPF:

<Button HorizontalAlignment="Left" Height="40" Width="40" FontFamily="Arial Black" Foreground="White" Margin="5,30,0,0" fa:Awesome.Content="Folder">
    <StackPanel>
        <TextBlock>
            My Folders
        </TextBlock>
    </StackPanel>
</Button>

      

Now the problem is that it only shows "My folders" and the "font-size" icon is gone - I can confirm that the icon works (when I delete the textbox it displays).

+3


source to share


2 answers


This line

fa:Awesome.Content="Folder"

      



Works by setting ContentControl.Content

the target symbol to the icon. Therefore, it sets the Button.Content

symbol representing the folder icon in your case. But with the following statement, you overwrite Button.Content

with a new value (set it to StackPanel

), so the icon is gone. If you want a button with an icon and text - create another text block inside your StackPanel and use it for the icon and then remove fa:Awesome.Content="Folder"

from the button itself. Or is it better to use FontAwesome control instead of TextBlock, for example:

<Button HorizontalAlignment="Left"
        Height="40"
        Width="300"
        FontFamily="Arial Black"
        Foreground="White"
        Margin="5,30,0,0">
    <StackPanel Orientation="Horizontal">
        <fa:FontAwesome Icon="Folder" Margin="0,0,5,0"/>
        <TextBlock>My Folders</TextBlock>
    </StackPanel>
</Button>

      

+5


source


Try the following:

<Button HorizontalAlignment="Left" Height="40" Width="40" FontFamily="Arial Black" Foreground="White" Margin="5,30,0,0">
<StackPanel>
    <fa:ImageAwesome Icon="Folder"/>
    <TextBlock>
        My Folders
    </TextBlock>
</StackPanel>

      



0


source







All Articles