Xamarin形成圆形按钮

时间:2019-07-25 13:09:28

标签: xaml xamarin xamarin.forms visual-material

我正在使用Xamarin Forms 4.1.0.581479和相同版本的Xamarin Forms Visual Material。

我制作了一个圆形按钮,用作几个模式叠加的关闭按钮。看起来像这样:

enter image description here

问题是我不能使中间的x(从“材质”图标字体)变大。目前它的字体大小为20

一旦我开始增加字体大小,例如到30,这种情况开始发生:

enter image description here

我尝试将按钮的Padding设置为零,尝试使用Horizo​​ntalOption,尝试将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>

1 个答案:

答案 0 :(得分:3)

我认为您应该使用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>