Text inside a button disappears if button width is under a certain value

BobG 41 Reputation points
2022-05-27T10:39:22.347+00:00

Hi,

I'm trying to build a login form, this form is set as "WindowStyle=none" and "ResizeMode=NoResize" so Minimize, Maximize and Close buttons are not visible.
To let the user close the login form (and thus close the application if it doesn't login) I would like to put a Button on the upper right corner with a "X" inside, "simulating" the close button.
I'm able to set the button but if I set Width under 40 the "X" disappears.
This is how I've set the button (I'm using MaterialDesign XAML):

<Button Style="{StaticResource MaterialDesignFlatLightBgButton}" Width="40" Height="20" Background="White" BorderThickness="1" Margin="357,3,0,0">
                    <TextBlock Text="X"  Foreground="Black" FontFamily="Century Gothic" FontSize="12" FontWeight="Bold"/>                
</Button>

I thought to "Left" align the text or set a "Margin" and then reduce the Width of the button but the text is always centered inside the button and if I set Width=30 (for example) the text disappears.
Surely I'm doing something wrong (I'm new with WPF) but can't figure out what !
Thank you, regards.

Roberto

Developer technologies Windows Presentation Foundation
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2022-05-27T12:46:15.717+00:00

    Try adding Padding="0" to <Button>.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. BobG 41 Reputation points
    2022-05-27T13:14:30.363+00:00

    It worked, thank you.
    Regards,

    Roberto

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.