c# - Xamarin.forms 自定义按钮控件
问题描述
我使用侧边栏的按钮,没有使用列表视图,如果我设置高度请求以降低高度文本将重叠,是否有任何方法可以使用自定义渲染或其他方式降低高度?
这是我的代码
<!--<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 按钮具有较大的 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 预发行版中。
推荐阅读
- python - 字典中增加的参数
- javascript - 如何告诉 Javascript 哪个选项卡处于活动状态
- pinot - Pinot 嵌套 json 摄取
- ruby-on-rails - Rails 6 + Ruby 2.7 - 我如何跟踪我的视频/图像上传大小,以便我知道总共上传了多少 MB 文件
- c# - 如何仅将随机速度放在 y 轴的位置上?
- javascript - 幻灯片错误“RangeError:超出最大调用堆栈大小
- python - geemap库地图插图应该怎么做?
- git - 使用详细和消息标志的 git commit 不起作用
- python - TypeError:无法将“torch.uint8”解释为数据类型
- python - 转换时间带走