C# Xamarin.forms自定义按钮控件
我需要减少按钮之间的空间 我使用了侧栏按钮,没有使用列表视图,如果我设置了高度请求以减少高度文本将重叠,是否有任何方法使用自定义渲染或其他方式来减少高度 这是我的密码C# Xamarin.forms自定义按钮控件,c#,asp.net,xaml,xamarin.forms,C#,Asp.net,Xaml,Xamarin.forms,我需要减少按钮之间的空间 我使用了侧栏按钮,没有使用列表视图,如果我设置了高度请求以减少高度文本将重叠,是否有任何方法使用自定义渲染或其他方式来减少高度 这是我的密码 <!--<Grid BackgroundColor="#783271" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> <Grid.ColumnDefinition
<!--<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属性,但同时减少填充。默认情况下,与iOS相比,Android按钮具有较大的高度请求和填充。请尝试以下操作:
<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预发行版中 一个简单的解决方案是使用您提到的HeightRequest属性,同时减少填充。默认情况下,与iOS相比,Android按钮具有较大的高度请求和填充。请尝试以下操作:
<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预发行版中 Stacklayout有自己的子级间距。尝试将stacklayout的间距设置为0。i、 e.父stacklayout的间距为0。@我尝试使用间距为0,但它没有为其子项设置自己的间距。尝试将stacklayout的间距设置为0。i、 e.对于父stacklayout,spacing=0。@Shaw我尝试了spacing=0,但没有解决问题,实际上我没有看到您最后两行的答案Xamarin.forms版本可能会生效,我会检查感谢您的支持。一旦我更新了xamarin.forms版本,它是否会影响现有的代码和函数?如果您已经使用了版本3,我认为不会有任何问题。如果您使用的是版本2,我不确定。是的,它可以工作,当我更新xamarin.forms版本时,谢谢您解决这个问题,实际上我没有看到您最后两行的答案xamarin.forms版本可能会生效,我会检查感谢您的支持。一旦我更新了xamarin.forms版本,它是否会影响现有的代码和函数?如果您已经使用了版本3,我认为不会有任何问题。如果您使用的是版本2,我不确定。是的,当我更新xamarin.forms版本时,它可以工作。谢谢