xaml - Xamarin 窗体圆形按钮
问题描述
我正在使用 Xamarin Forms 4.1.0.581479 和相同版本的 Xamarin Forms Visual Material。
我制作了一个圆形按钮,用作几个模态叠加层的关闭按钮。它看起来像这样:
问题是我不能使中间的 x(来自 Material 图标字体)更大。目前它的字体大小为 20
一旦我开始增加字体大小,例如增加到 30,就会开始发生这种情况:
我尝试将按钮的 Padding 设置为零,我尝试使用 HorizontalOption,我尝试将 BorderWidth 设置为 0,但似乎没有任何区别。
如何在不剪裁图标的情况下增加字体大小?
根据要求,这是我的 XAML:
<Button Grid.Column="1" Text="{x:Static constants:IconFont.Close}" Clicked="OnClicked" Style="{StaticResource CloseButton}" />
CloseButton
样式如下:
<Style x:Key="CloseButton" TargetType="Button">
<Setter Property="FontFamily" Value="{StaticResource MaterialFontFamily}" />
<Setter Property="BackgroundColor" Value="#0075BE" />
<Setter Property="FontSize" Value="20" />
<Setter Property="WidthRequest" Value="50" />
<Setter Property="HeightRequest" Value="50" />
<Setter Property="HorizontalOptions" Value="End" />
<Setter Property="BorderRadius" Value="25" />
</Style>
解决方案
我认为你应该使用 ImageButton 而不是 Button:
<ImageButton VerticalOptions="Center" HorizontalOptions="Center" BackgroundColor="AliceBlue" CornerRadius="25" WidthRequest="50" HeightRequest="50">
<ImageButton.Source>
<FontImageSource
FontFamily="{DynamicResource MaterialFontFamily}"
Glyph="{DynamicResource IconClose}"
Size="30"
Color="Red" />
</ImageButton.Source>
</ImageButton>
推荐阅读
- javascript - 如何移动传单图层?
- html - 在表格行显示时更改隐藏表格行中表格数据的样式
- javascript - 你如何从firestore读取数据?
- python - 如何通过函数返回字典?
- forms - 如何在表单上创建浮动标签
- yacc - yacc 中的一元运算符优先级
- python - How to search by user_id or user_name in Tweepy?
- python - How to convert interger to time while the interger is actually time data but no separation
- java - Java 强制对象::toString
- c - What do the parameters mean in scull's proc read implementation?