xamarin 如何在xaml中删除项目之间的边距?

kmb7vmvb  于 2022-12-07  发布在  其他
关注(0)|答案(4)|浏览(147)

This is my xaml code:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:TestSalesforce"
             x:Class="TestSalesforce.MainPage">

    <StackLayout Padding="0,0,0,0">
        <!-- Place new controls here -->
        <Label Text="LOGIN" 
           HorizontalOptions="Center" />
        <Label Text="Email:" Margin="0,0,0,0"/>
        <Entry x:Name="txtEmail" Margin="0,0,0,0"/>
        <Label Text="Password:" Margin="0,0,0,0"/>
        <Entry x:Name="txtPassword" Margin="0,0,0,0"/>
        <Button x:Name="btnLogin" Text="Login"/>
        <Button x:Name="btnClose" Text="Close" Clicked="OnClose"/>
    </StackLayout>
</ContentPage>

I try using Margin="0,0,0,0" but it not ok: This is result:

How can remove margin between items in xaml?

oyxsuwqo

oyxsuwqo1#

StackLayoutGridSpacing-属性。间距描述了布局中每个子元素之间差距。我认为默认情况下,StackLayoutsSpacing-属性不是0,而是2-5附近的某个属性。请尝试在stacklayout上设置Spacing="0"

mccptt67

mccptt672#

您似乎已将样式应用于这些元素。可以尝试将这些元素的填充设置为0(它们可能不支持填充),如果这样做不起作用,则可能需要添加负边距以抵消这些样式。

rta7y2nd

rta7y2nd3#

请尝试以下代码:使用网格格式

<Grid Grid.Row="3">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Controls:Label Grid.Row="0" Font="15" Text="{Binding LabelAddress}"/>
        <StackLayout>
            <Controls:PlaceholderEditor Grid.Row="1" Text="{Binding TextAddress}" VerticalOptions="FillAndExpand" HorizontalOptions="Fill" Margin="0,20,0,0"  Placeholder="Enter Address" PlaceholderColor="{StaticResource LightGray}" AutoSize="TextChanges"/>
        </StackLayout>
    </Grid>

结果是这样的:

hec6srdp

hec6srdp4#

Spacing=0添加到堆栈布局中,使其看起来如下所示:<StackLayout Spacing=0 Padding="0,0,0,0">

相关问题