Forum Xamarin Cross Platform with Xamarin

MVVM Light ObserveSourceEvent gives me InvalidCastException

As the title says, I'm getting an InvalidCastException, having the following code

                    () => DurationSeekBar.Progress,
                    () => ViewModel.VisitRequest.Duration)
                    .ConvertSourceToTarget(seekBarProgress => new TimeSpan(0, seekBarProgress * 15, 0))

The thing is, it should just be updating the value on the viewmodel (according to me, haha) yet, it isn't as soon as it reaches the call to ObserveSourceEvent, a InvalidCastException is thrown, even if no casting is needed between properties of the binding (Binding<string,string>) this happens..

Any thoughts?


  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    A TimeSpan constructor takes 3 int the way you're using it.
    Is it possible that seekBarProgress is a double or decimal and that its value * 15 is returned back other than an int, making that the invalid cast? try (int)(seekBarProgress*15) just to be safe. May not solve it but it can't break it.

  • RyanPalmer.0677RyanPalmer.0677 USMember ✭✭
    edited October 2017

    Probably too late for you but I had the same issue a moment ago - digging in the MVVM Light source gave me the hint. You need to set the type of the EventArgs for ObserveSourceEvent, like this:

Sign In or Register to comment.