其他分享
首页 > 其他分享> > 自定义可见性转换器-Android-版本(MvvmCross)

自定义可见性转换器-Android-版本(MvvmCross)

作者:互联网

我已经使用MvvmCross开发了适用于Android的应用程序.它的一部分应该显示ImageView或MvxImageView.当我在调试模式下对其进行测试时,它工作正常,但是当我将其更改为发布模式时,可见性转换器似乎停止工作.所有其他转换器都按应有的方式工作,只有那些转换器停止工作.

我的xml简历:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical">
    <ImageView
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:scaleType="fitCenter"
        local:MvxBind="Visibility MyObject, Converter=ByteInverseVisibility; AssetImagePath MyObject, Converter=AttachmentTypeToSource" />
    <Mvx.MvxImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:maxHeight="150dp"
        android:adjustViewBounds="true"
        local:MvxBind="Visibility MyObject, Converter=ByteVisibility; Bitmap MyObject.Attachment, Converter=InMemoryImage" />
</LinearLayout>

转换器:

public class ByteVisibilityConverter : MvxBaseVisibilityValueConverter<MyObjectClass>
{
    protected override MvxVisibility Convert(MyObjectClass value, object parameter, CultureInfo culture)
    {
        if (value.AttachType == AttachmentType.Photo && value.Attachment != null)
        {
            return MvxVisibility.Visible;
        }

        return MvxVisibility.Collapsed;
    }
}

public class ByteInverseVisibilityConverter : MvxBaseVisibilityValueConverter<MyObjectClass>
{
    protected override MvxVisibility Convert(MyObjectClassvalue, object parameter, CultureInfo culture)
    {
        if (value.AttachType != AttachmentType.Photo || value.Attachment == null)
        {
            return MvxVisibility.Visible;
        }

        return MvxVisibility.Collapsed;
    }
}

解决方法:

原因是包装中未包含“可见性”属性.

您必须添加类似以下内容:

public void Include(ImageView imageView)
    {
        imageView.Visibility = imageView.imageView;
    }

在您的LinkerPleaseInclude.cs文件中.

标签:xamarin-android,mvvmcross,android
来源: https://codeday.me/bug/20191029/1957247.html