Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add text to a button with an icon

Tags:

c#

uwp

uwp-xaml

I have a button with the Feedback Hub icon (Segoe MDL2 Assets), and I wanted to add the text: "Feedback", after the icon, but since I already have the icon it is possible to add the text? Here is an example of my button:

<Button x:Name="feedbackButton" FontFamily="Segoe MDL2 Assets" Content="&#xE939;" Click="feedbackButton_Click"/>

I try: Content="&#xE939; Feedback";, but the word "Feedback" dont appears!

like image 706
Fernando Sousa Avatar asked May 29 '17 10:05

Fernando Sousa


People also ask

How do you add text under icon in Flutter?

Step 1: Add the Row widget inside the ElevatedButton. Step 2: Add the Text('Download') width inside the Row. Step 3: Then add the SizedBox(width: 5,) followed by the actual icon widget i.e. Icon(Icons.

How do I create a button with icon and text in Flutter?

You can achieve that by using a FlatButton that contains a Column (for showing a text below the icon) or a Row (for text next to the icon), and then having an Icon Widget and a Text widget as children.

How do you add an icon to an elevated button in Flutter?

You can simply add ElevatedButton. icon() widget, you will get the icon property where you can pass Icon data to add Icon on Elevated Button.


2 Answers

Try putting the icon text and text in separate Runs of a TextBlock like this -

<Button>
    <TextBlock>
        <Run Text="&#xE939;"
             FontFamily="Segoe MDL2 Assets" />
        <Run Text="Feedback" />
    </TextBlock>
</Button>

Update

Isn't this what the OP wanted? Why the downvote??

enter image description here

like image 143
Justin XL Avatar answered Oct 04 '22 12:10

Justin XL


You can place a StackPanel inside your Button and then add as many TextBlocks into your StackPanel as you need:

   <Button x:Name="feedbackButton" Click="feedbackButton_Click">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="&#xE939;" FontFamily="Segoe MDL2 Assets" VerticalAlignment="Center"/>
            <TextBlock Text="Feedback" VerticalAlignment="Center" Margin="8,0,0,0"/>
        </StackPanel>
    </Button>
like image 45
A. Milto Avatar answered Oct 04 '22 11:10

A. Milto