mvvmcross binding on switch fails on release
Asked Answered
T

2

8

I have a weird bug in my MVVMCross app.

Considering the following scenario:

<Switch
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="false"
    android:clickable="false"
    android:layout_alignParentRight="true"
    android:id="@+id/activatedSwitch"
    local:MvxBind="Checked IsActive" />
  • Compile version: level 14
  • Minimum version: level 14
  • Target version: level 14

  • Linking: Sdk Assemblies Only

  • Android Phone version is 4.1.2.

When I run the app in Debug mode, all is ok.

But when I run it in Release, the binding to the Checked property failed with the following error:

E/MvxBind (11670): 12,70 View type not found - Switch

Tailback answered 2/2, 2014 at 0:3 Comment(0)
D
14

Since MvvmCross uses reflection to perform databinding, the linker is not seeing the Checked property and is not including it in your binary. There is a file name LinkerPleaseInclude.cs that you can edit to add a reference to this property.

Something like:

public void Include(Switch @switch)
{
    @switch.CheckedChange += (sender, args) => @switch.Checked = [email protected];
}
Debunk answered 2/2, 2014 at 2:17 Comment(2)
why do we need @ sign in the param?Matronize
Because "switch" is a reserved keyword in C# (switch/case). The @ allows you to use reserved keywords as an identifier. learn.microsoft.com/en-us/dotnet/csharp/language-reference/…Debunk
S
0

The latest version of MVVMCross has this issue addressed. The below code is only enough.
Note:- MvvmCross 7.0. I am using. But I suspect this could be addressed in before releases.

local:MvxBind="Checked IsActive"
Sidsida answered 8/3, 2021 at 6:23 Comment(1)
Well, the solution I work on is on MvvmCross 7.1.2 and I had to use the LinkerPleaseInclude trick. Otherwise it stays broken in Release mode.Numerous

© 2022 - 2024 — McMap. All rights reserved.