簡體   English   中英

Xamarin.forms自定義按鈕控件

[英]Xamarin.forms custom button control

我需要減少按鈕之間的空間 在此處輸入圖片說明

我使用了側欄按鈕,沒有使用列表視圖,如果我設置了降低高度的請求,文字將重疊,請問是否可以使用自定義渲染或其他方式降低高度?

這是我的代碼

            <!--<Grid BackgroundColor="#783271"  VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="20"/>

                </Grid.RowDefinitions>

                <Button Grid.Column="0"  Grid.Row="0" Text="Client Expertential Plan" TextColor="#636363" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" BorderWidth="0" BackgroundColor="White" FontSize="Small" FontAttributes="Italic"/>
                <Button Grid.Column="0"  Grid.Row="1" Text="Organisation / Template Library" TextColor="#636363" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" BorderWidth="0" BackgroundColor="White" FontSize="Small"  FontAttributes="Italic"/>
                <Button Grid.Column="0"  Grid.Row="2" Text="Use Expertential Plan" TextColor="#636363" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" BorderWidth="0" BackgroundColor="White" FontSize="Small"  FontAttributes="Italic"/>

            </Grid>-->

            <!--<local:CustomButton Text="hai"></local:CustomButton>-->
            <Button Text="Client Expertential Plan" TextColor="#636363" VerticalOptions="FillAndExpand" HorizontalOptions="Start" BorderWidth="0" BackgroundColor="White" FontSize="Small" FontAttributes="Italic"/>
            <Button Text="Organisation / Template Library" TextColor="#636363" VerticalOptions="FillAndExpand" HorizontalOptions="Start" BorderWidth="0" BackgroundColor="White" FontSize="Small"  FontAttributes="Italic"/>
            <Button Text="Use Expertential Plan" TextColor="#636363" VerticalOptions="FillAndExpand" HorizontalOptions="Start" BorderWidth="0" BackgroundColor="White" FontSize="Small"  FontAttributes="Italic"/>
            <!--<Label x:Name="lblClientExpPlan"  Text="Client Expertential Plan" TextColor="#737373" VerticalOptions="FillAndExpand" HorizontalOptions="StartAndExpand"/>
            <Label  x:Name="lblOrgTemLib" Text="Organisation / Template Library" TextColor="#737373" VerticalOptions="FillAndExpand" HorizontalOptions="StartAndExpand"/>
            <Label  x:Name="lblUseExpPlan" Text="Use Expertential Plan" TextColor="#737373" VerticalOptions="FillAndExpand" HorizontalOptions="StartAndExpand"/>-->
        </StackLayout> 

一個簡單的解決方案是使用您提到的HeightRequest屬性,同時減少Padding。 與默認情況下的iOS相比,Android按鈕的HeightRequest和Padding較大。 請嘗試以下操作:

<StackLayout.Resources>
    <ResourceDictionary>
        <Style TargetType="Button" >
            <Setter Property="HeightRequest" Value="30" />
            <Setter Property="Padding" Value="10, 5" />
            <Setter Property="FontSize" Value="Small" />
            <Setter Property="BorderWidth" Value="0" />
            <Setter Property="VerticalOptions" Value="Start" />
            <Setter Property="HorizontalOptions" Value="Start" />
            <Setter Property="BackgroundColor" Value="White" />
            <Setter Property="TextColor" Value="#636363" />
            <Setter Property="FontAttributes" Value="Italic" />
        </Style>
    </ResourceDictionary>
</StackLayout.Resources>

<Button Text="Client Expertential Plan" />
<Button Text="Organisation / Template Library" />
<Button Text="Use Expertential Plan" />

padding屬性是Button控件的最新添加。 它存在於Xamarin.Forms 3.2預發行版中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM