Try adding Padding="0" to <Button>.
Text inside a button disappears if button width is under a certain value
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
1 additional answer
Sort by: Most helpful
-
BobG 41 Reputation points
2022-05-27T13:14:30.363+00:00 It worked, thank you.
Regards,Roberto