简体   繁体   中英

MvvmCross Android Linking Issue on Visibility Converter

I know there are linking issues with Android and I know about using the LinkerPleaseInclude. However I am not sure what to put into the LinkerPleaseInclude.cs file for the problem I am seeing.

I have a view which uses the Visibility converter to use a boolean IsBusy property to determine whether a number of controls should be displayed or not . I am using a ProgressBar, a TextView and an ImageView. I have tried a number of combinations to get the linker issue fixed.

When deployed as debug it all works, it is just a release issue.

So for example my progressBar is defined as follows (The Visibility converter is used the same way for the other controls)

<ProgressBar
        android:id="@+id/pbHeaderProgress"
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"
        local:MvxBind="Visibility Visibility(IsBusy)" />

I have added the following to my LinkerPleaseInclude.cs. I have not included the whole file for brevity

    public void Include(ProgressBar progressBar)
    {
        progressBar.Visibility = ViewStates.Invisible;
    }

    public void Include(TextView textView)
    {
        textView.TextChanged += (sender, args) => textView.Text = "" + textView.Text;
        textView.Hint = "" + textView.Hint; 
        textView.Visibility = ViewStates.Invisible;
    }

    public void Include(ImageView imageView)
    {
        imageView.Visibility = ViewStates.Invisible;
        imageView.Visibility = ViewStates.Visible;
        imageView.Visibility = ViewStates.Gone;
    }

    public void Include(MyViewModel viewModel)
    {
        viewModel.PropertyChanged += (sender, args) => { };
    }

    public void Include(MvxVisibilityValueConverter converter)
    {
        converter.Convert(null, null, null, null);
    }

None of these seem to work. CAn someone help me with this and let me know what I should put in to get the Visibility to work

The problem was that when building a release version of an Android application you sometimes find that some of the behaviour does not work. This is due to the way it links the program. I believed it optimises in a way that removes code that it thinks it is not using. To fix it in an MvvmCross based app you have to add the calls to the code that you think it has optimised away. This is done by using the LinkerPleaseInclude.cs file and adding calls to the "missing" code. In this case visibility on a ProgressBar control was not working. I had tried adding code to the LinkerPleaseInclude.cs file but it was not working. I found the solution and added as an answer.

I put the following code into the LinkerPleaseInclude.cs. I think it works because it uses both the setter and getter

public void Include(ProgressBar ProgressBar)
{
   progressBar.Visibility = !progressBar.Visibility;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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