Gaius
Gaius

Reputation: 15

MVVMCross Bound Button event not triggering on press

I have an iOS appointment app running against Mono 2.10.11 in Xamarin Studio.

The appointment detail screen allows appointments to be rated based on their outcome. A button to allow the rating is displayed based on a boolean set based on business logic. The bound button triggers the opening of the rating screen. It works normally in iOS 6.1 on Mobile and Debugger and on iOS 7 simulator. It does not work on an iOS 7 device.

The AppointView.cs contains the function ViewDidLoad which sets up the button as follows: -

AppointmentViewTable.Source = _source;

this.AddBindings (new Dictionary<object, string>
{
    { _source, "{'ItemsSource':{'Path':'AppointmentDetails'}, 'HeaderTitle':{'Path':'Appointment.AppointmentDate','converter':'DateTime'}}" },
    { btnRateSession, "{'Hidden':{'Path':'Appointment.RateAvailable','converter':'InvertedVisibility'}, 'Title':{'Path':'TextSource','Converter':'Language','ConverterParameter':'btnRateSession'}, 'TouchDown':{'Path':'GoToSessionRateView'}}"}
});

On running the program through creation of the appointment view I get the following warning: -

2013-10-18 16:58:55.012 M2FitiOS[3773:a0b] MvxBind: Error:  14.12 Problem seen during binding execution for from Appointment.RateAvailable to Hidden - problem InvalidCastException: Null object can not be converted to a value type.
at System.Convert.ToType (System.Object value, System.Type conversionType, IFormatProvider provider, Boolean try_target_to_type) [0x00017] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Convert.cs:2553 
at System.Convert.ChangeType (System.Object value, System.Type conversionType, IFormatProvider provider) [0x00017] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Convert.cs:2204 
at Cirrious.MvvmCross.Binding.ExtensionMethods.MvxTypeExtensions.MakeSafeValue (System.Type propertyType, System.Object value) [0x00000] in <filename unknown>:0 
at Cirrious.MvvmCross.Binding.Bindings.Target.MvxPropertyInfoTargetBinding.SetValue (System.Object value) [0x00000] in <filename unknown>:0 
at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (Boolean isAvailable, System.Object value) [0x00000] in <filename unknown>:0

The AppointmentViewModel contains the event :-

public ICommand GoToSessionRateView
{
    get
        {
            return new MvxRelayCommand(() => RequestNavigate<SessionRateViewModel>(new { appointmentId = _appointmentId }));
        }
    }

Not sure what has caused the event to stop working. Any pointers would be appreciated.

Upvotes: 1

Views: 572

Answers (1)

Stuart
Stuart

Reputation: 66882

Generally things not working on devices are due to the Xamarin "linker" and can be worked around using a number of options - see Trouble with xamarin.ios/monotouch , mvvmcross and linking

When this happens my preferred option is to use a LinkerPleaseInclude.cs file - like https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/ApiExamples/ApiExamples.Touch/LinkerPleaseInclude.cs

If this is the problem in your case, then you would need to ensure that LinkerPleaseInclude includes a TouchDown reference - although you may be happier if you actually change the binding to TouchUpInside instead.


Meanwhile, the trace you have is showing an error in Appointment.RateAvailable to Hidden - I'm confused why that should be different on ios7. I suspect the easiest way to solve it in this old version of MvvmCross, might be to upgrade... although it might also be possible that simply changing the converter to a Converter might help.

Upvotes: 4

Related Questions