Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何调整xaml标签中的填充_Xaml_Label_Padding - Fatal编程技术网

如何调整xaml标签中的填充

如何调整xaml标签中的填充,xaml,label,padding,Xaml,Label,Padding,如何使下面标签中的顶部和底部填充更小?在我看来,边界框比它需要的大得多,但是填充被设置为0,所以它不能再小了 <Label Background="AliceBlue" Content="1800" FontSize="170" FontWeight="Bold" Foreground="Gray" Padding="0" /> 填充在框架元素的XAML中不存在。使用边距 填充可以应用于三个元素:块、边框和控件,因为这些元素有一个外缘。您可以使用边距 使用边距,您可以设置要向左、向

如何使下面标签中的顶部和底部填充更小?在我看来,边界框比它需要的大得多,但是填充被设置为0,所以它不能再小了

<Label Background="AliceBlue" Content="1800" FontSize="170" FontWeight="Bold" Foreground="Gray" Padding="0" />

填充在
框架元素的XAML中不存在。使用边距

填充可以应用于三个元素:
边框
控件
,因为这些元素有一个外缘。

您可以使用边距

使用边距,您可以设置要向左、向右、上、下移动的金额

我的意思是
Margin=“0,0,0,0”
这意味着。你从来没有这样过

它的顺序如下:
Margin=“左、上、右、下

所以如果我有
margin=“2,5,3,5”


这意味着我有一个从左边2像素的边距,从上面5像素的边距,从右边3像素的边距,从底部5像素的边距。

刚刚点击标签周围有边框的地方,我设置了一个负边距

<Border BorderBrush="Black" BorderThickness="1">
    <Label Margin="-5" Content="Unable to report/>
</Border>


如果可以更改为使用TextBlock,则可以更好地控制填充。标签的用途似乎是通过其内部样式固定填充。请参阅
“”。

尝试将标签包装在布局中,例如StackLayout,并为该布局添加填充,然后标签将相应对齐。此代码可能会对您有所帮助

<StackLayout Padding="10">
    <Label x:Name="TitleLbl"></Label>
</StackLayout> 

制作自定义渲染器 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); }
        }
}
Control.SetPadding((int)saElement.Padding.Left, (int)saElement.Padding.Top, (int)saElement.Padding.Right, (int)saElement.Padding.Bottom);
android中的

 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); }
        }
}
Control.SetPadding((int)saElement.Padding.Left, (int)saElement.Padding.Top, (int)saElement.Padding.Right, (int)saElement.Padding.Bottom);

通过设置边距并将其包装到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>

Hello Bjarne,我也有同样的问题,你找到解决方案了吗?其他人知道解决方案吗?当使用较大的字体大小(例如20)时,你可以最好地看到这种效果。如果我使用margin margin=“5,0,0,0”,则标签会向右移动,但我只想移动文本。