Search code examples
c#xamlbuttontextblockstackpanel

TextBlock doesnt use all the space in button xaml C#?


My textblock doesnt use the whole space inside the button, I need to decrease fontsize to be able to see it but I dont want to do that. It's getting too small. Isn't there a way to use this space in the button?

 <Button BorderThickness="0" 
         x:Name="btnBalance" 
         Click="btnBalance_Click"
         Grid.Column="1"
         Margin="0,0,0,-5">

         <StackPanel Orientation="Vertical" 
                     HorizontalAlignment="Center"
                     VerticalAlignment="Center">

                     <TextBlock Text="&#xE80C;" 
                                   FontSize="40" 
                                   FontFamily="/Fonts/fontello.ttf#fontello"
                                   HorizontalAlignment="Center"/>
                    <TextBlock Text="{Binding LocalizedResources.CARD_OPERATIONS, 
                                   Source={StaticResource LocalizedStrings}}" 
                                   FontSize="17"
                                   HorizontalAlignment="Center"
                                   FontFamily="/Fonts/opensansregular.ttf#Open Sans"
                                   Margin="0,0,0,2"/>
        </StackPanel>
</Button>

Buttons are positioned equally within grid:

 <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
  </Grid.ColumnDefinitions>

Solution

  • The textblock is inside the stackpanel, so if you want it more readable, just change the stackpanel's properties. This might do it:

    <Button BorderThickness="0" 
         x:Name="btnBalance" 
         Click="btnBalance_Click"
         Grid.Column="1"
         Margin="0,0,0,-5">
    
         <StackPanel Orientation="Vertical" 
                     HorizontalAlignment="Center"
                     VerticalAlignment="Center"
    
        Height="150" Margin="-10,-10,0,0" Width="150" <!--These part-->
        >
    
                     <TextBlock Text="&#xE80C;" 
                                   FontSize="40" 
                                   FontFamily="/Fonts/fontello.ttf#fontello"
                                   HorizontalAlignment="Center"/>
                    <TextBlock Text="{Binding LocalizedResources.CARD_OPERATIONS, 
                                   Source={StaticResource LocalizedStrings}}" 
                                   FontSize="17"
                                   HorizontalAlignment="Center"
                                   FontFamily="/Fonts/opensansregular.ttf#Open Sans"
                                   Margin="0,0,0,2"/>
        </StackPanel>
    </Button>
    

    If it doesn't do what you want, change the Height="150" Margin="-10,-10,0,0" Width="150" part to resize and reposition the stackpanel.