简体   繁体   English

Image Converter无法在Xamarin.Forms中使用

[英]Image Converter not working in Xamarin.Forms

Im using the converter to change the image but image is not loading here can somebody please help me here what I'm done wrong? 即时通讯使用转换器来更改图像,但图像未在此处加载有人可以帮我解决我做错了什么吗? I had checked the converter by debugging it is not getting hit. 我已经调试了转换器,但没有遇到问题。

Converter Code: 转换器代码:

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;
    }
}

In Xaml 在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 .}" />

In Code behind file 在文件后面的代码中

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

The Binding in my knowledge is not working because the boolean is in the ViewModel and not accessible to the listview data template 据我所知,绑定不起作用,因为布尔值位于ViewModel中,并且不能由listview数据模板访问

Try using this: 尝试使用此:

 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