【发布时间】:2019-01-17 21:07:25
【问题描述】:
这个post 展示了如何使 SvgCachedImage 像一个按钮一样工作。但是,如何将 SvgCachedImage 加载到 XamarinForm 的 ImageButton Source 中?
我的非工作代码:
<?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>
代码隐藏:
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;
}
}
}
【问题讨论】:
-
据我所知,FFImageLoading SVG和Image button是不同的控件,只能设置ImageButton图片源。为什么不能使用 FFImageLoading SVG 和点击手势事件?
-
我很困惑,这是两个不同的控件,你到底想在这里实现什么
-
@G.hakim 我正在尝试让 ImageButton 加载 SVG 图标。
-
@ДенисЧорный ,使用带有点击手势事件的 FFImageLoading SVG,我失去了 ImageButton 的功能(例如设置圆角边框等)。我正在寻找的解决方法是让 FFImageLoading 在内存中预渲染 ImageButton 可以接受的图像。
-
好吧,我不知道你能不能做到这一点,我很确定你不能,但祝你好运
标签: xamarin.forms ffimageloading