MvvmCross Android Linking Issue on Visibility Converter

白昼怎懂夜的黑 提交于 2019-12-23 15:24:21

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/27252009/mvvmcross-android-linking-issue-on-visibility-converter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!