Xamarin.forms 加载FFImageLoading SVG到ImageButton源代码?
这显示了如何使SvgCachedImage像按钮一样工作。但是,如何将SvgCachedImage加载到XamarinForm的ImageButton源中 我的非工作代码:Xamarin.forms 加载FFImageLoading SVG到ImageButton源代码?,xamarin.forms,ffimageloading,Xamarin.forms,Ffimageloading,这显示了如何使SvgCachedImage像按钮一样工作。但是,如何将SvgCachedImage加载到XamarinForm的ImageButton源中 我的非工作代码: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winf
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:SharedSvgSample"
x:Class="SharedSvgSample.MainPage"
xmlns:ffimageloadingsvg="clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms">
<StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
<ImageButton
x:Name="myButton"
HeightRequest="200"
Clicked="myButton_Clicked"
WidthRequest="200" />
</StackLayout>
</ContentPage>
不幸的是,
Xamarin.Forms.Button
只支持FileImageSource,所以目前不能将SVG加载到按钮图像中
但是,您可以只加载SVG图像,然后添加TapGestureRecognitor来模拟按钮。正如我所知,FFImageLoading SVG和image Button是不同的控件,您只能设置ImageButton图像源。为什么不能将FFIMAGELOADINGSVG与点击手势事件一起使用?我在这里感到困惑,这是两种不同的控件,您到底想实现什么here@G.hakim我正试图让ImageButton加载SVG图标。@cfццццццц,使用FFImageLoading SVG with tap手势事件,我丢失了ImageButton的功能(如设置圆形边框等)。我正在寻找的解决方法是使用FFImageLoading在内存中预渲染ImageButton可以接受的图像。我不知道您是否可以这样做,我很确定您不能,但祝您好运找到它。我指的是
Xamarin.Forms.ImageButton
。我更关注使用FFImageLoading在-m中预渲染svg图标的解决方法emory指向ImageButton可以接受的图像。@JesonMartajaya找到解决方案了吗?
using FFImageLoading.Svg.Forms;
using System;
using Xamarin.Forms;
namespace SharedSvgSample
{
public partial class MainPage : ContentPage
{
private bool _myButtonValue;
private SvgImageSource _visibilityOn = null;
private SvgImageSource _visibilityOff = null;
public MainPage()
{
InitializeComponent();
_visibilityOn = SvgImageSource.FromResource("SharedSvgSample.Resources.visibility_on.svg");
_visibilityOn.VectorHeight = 100;
_visibilityOn.VectorWidth = 100;
_visibilityOff = SvgImageSource.FromResource("SharedSvgSample.Resources.visibility_off.svg");
_visibilityOff.VectorHeight = 100;
_visibilityOff.VectorWidth = 100;
myButton.Source = _visibilityOff;
}
private void myButton_Clicked(object sender, EventArgs e)
{
_myButtonValue = !_myButtonValue;
myButton.Source = _myButtonValue ? _visibilityOn.ImageSource : _visibilityOff.ImageSource;
}
}
}