繁体   English   中英

Image Converter无法在Xamarin.Forms中使用

[英]Image Converter not working in Xamarin.Forms

即时通讯使用转换器来更改图像,但图像未在此处加载有人可以帮我解决我做错了什么吗? 我已经调试了转换器,但没有遇到问题。

转换器代码:

public class DownloadIconConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return ((bool)value) ? "progressicon.png" : "cloud_download.png";
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return null;
    }
}

在Xaml中

  <ContentPage.Resources>
    <converter:DownloadIconConverter x:Key="downloadiconconverter" />
</ContentPage.Resources>

  <ImageButton
                                HeightRequest="40"  
                                    IsVisible="True"

                                Source="{Binding DownloadIcon,Converter={StaticResource downloadiconconverter}}"
                                WidthRequest="35" Command ="{Binding BindingContext.Download, Source={x:Reference listview}}" CommandParameter="{Binding .}" />

在文件后面的代码中

    public bool DownloadIcon
    {
        get { return downloadicon; }
        set { SetProperty(ref downloadicon, value); }
    }

据我所知,绑定不起作用,因为布尔值位于ViewModel中,并且不能由listview数据模板访问

尝试使用此:

 Source="{Binding BindingContext.DownloadIcon, Converter={StaticResource downloadiconconverter},Source={x:Reference listview}}"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM