【问题标题】:xamarin image button svg with text (size svg)带有文本的 xamarin 图像按钮 svg(大小 svg)
【发布时间】:2021-10-13 11:15:49
【问题描述】:

我想制作一个按钮,带有文本的图像按钮 svg。

在 xaml 中:

   <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:d="http://xamarin.com/schemas/2014/forms/design"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
         mc:Ignorable="d"
         x:Class="loginUI.L202">

<StackLayout VerticalOptions="Center" Spacing="50">


    <StackLayout.Resources>
        <ResourceDictionary>
            <Style TargetType="Button">
                <Setter Property="HorizontalOptions" Value="FillAndExpand"/>
            </Style>

            <Style TargetType="Image">
                <Setter Property="WidthRequest" Value="50"/>
            </Style>
        </ResourceDictionary>
    </StackLayout.Resources>

    <Button Text=" test" BackgroundColor="Wheat" BorderRadius="20" TextColor="red">
        <Button.Image>
            <OnPlatform x:TypeArguments="FileImageSource" Android="home.svg" iOS="home.svg"/>
        </Button.Image>
    </Button>

</StackLayout>

如何设置home.svg的尺寸(WidthRequest | HeightRequest)? TargetType="Image" 不起作用。

或者

有一种方法可以插入到按钮中,例如?

 <Button>  <Path Data="M185.255 512c-76.201 ....." /> </Button>

【问题讨论】:

    标签: xaml xamarin svg button xamarin.forms


    【解决方案1】:

    如果可以使用ImageButton,为什么还要使用Button

    &lt;ImageButton Source="img.xml" WidthRequest="100" HeightRequest="100" /&gt;

    但是,如果你想使用Button,那么:

    &lt;Button ImageSource="img.xml" WidthRequest="100" HeightRequest="100" /&gt;

    为什么是.xml

    因为您需要将 .svg 文件转换为 Vector 以用作 Button 的 ImageSource。使用this link 进行转换,然后将其添加到您的drawable 文件夹中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-15
      • 1970-01-01
      • 2018-10-04
      • 2018-02-08
      • 2020-08-27
      • 1970-01-01
      • 2012-08-09
      • 2017-05-04
      相关资源
      最近更新 更多