MVVM Light ObserveSourceEvent gives me InvalidCastException RRS feed

  • Question

  • User150116 posted

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

    _bindings.Add( this.SetBinding( () => DurationSeekBar.Progress, () => ViewModel.VisitRequest.Duration) .ConvertSourceToTarget(seekBarProgress => new TimeSpan(0, seekBarProgress * 15, 0)) .ObserveSourceEvent(nameof(SeekBar.ProgressChanged)));

    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) this happens..

    Any thoughts?

    Thursday, December 29, 2016 8:00 PM

All replies

  • User180523 posted

    @JesuCastillo 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.

    Thursday, December 29, 2016 8:11 PM
  • User93000 posted

    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:

    Thursday, October 12, 2017 1:27 PM