Reputation: 131
How can I make the top and bottom padding smaller in the following label? As I see it, the bounding box in much bigger than it needs to be, but the padding is set to 0, so it cannot be any smaller.
<Label Background="AliceBlue" Content="1800" FontSize="170" FontWeight="Bold" Foreground="Gray" Padding="0" />
Upvotes: 9
Views: 20568
Reputation: 1845
Adjust label padding by setting margin and wrapping it inside a StackLayout
<StackLayout VerticalOptions="StartAndExpand" Margin="0,0,0,0" BackgroundColor="Red">
<Label Text="Login to your account" TextColor="White" Margin="10,10,10,10" />
</StackLayout>
Upvotes: 1
Reputation: 2129
make custom renderer PCL:
public class SALabel : Label
{
public static readonly BindableProperty PaddingProperty = BindableProperty.Create("Padding", typeof(Thickness), typeof(SALabel),default(Thickness));
public Thickness Padding
{
get { return (Thickness)GetValue(PaddingProperty); }
set { SetValue(PaddingProperty, value); }
}
}
in android
Control.SetPadding((int)saElement.Padding.Left, (int)saElement.Padding.Top, (int)saElement.Padding.Right, (int)saElement.Padding.Bottom);
Upvotes: 1
Reputation: 950
Try to wrap the Label in a Layout for example StackLayout and give padding to that Layout, then Label will align accordingly. This code may helps you.
<StackLayout Padding="10">
<Label x:Name="TitleLbl"></Label>
</StackLayout>
Upvotes: 2
Reputation: 3509
You can use Margin.
With margin you can set the amount you want to go left, right, top, bottom
by this I mean Margin="0,0,0,0"
that means. you have none what so ever.
it goes by the following: Margin ="left, top, right, bottom
so if I have margin ="2,5,3,5"
it means I have a margin 2 pixels in from the left, 5 pixels in from the top, 3 pixels from the right and 5 pixels up from the bottom.
Upvotes: 4
Reputation: 696
If you can change to using TextBlock, then you can control the padding better. Label's purpose seems to be such that padding is fixed by its internal styling. See "How can I remove the margins around text in a WPF label?".
Upvotes: 0
Reputation: 8410
Having just hit this where a border was around the label I set a negative margin.
<Border BorderBrush="Black" BorderThickness="1">
<Label Margin="-5" Content="Unable to report/>
</Border>
Upvotes: 3
Reputation: 112
Padding does not exists in XAML on a FrameworkElement
. Use Margin.
Padding can be applied to three elements: Block
, Border
and Control
since these elements have an outer edge.
Upvotes: 2