Reputation: 471
I'm running into the following NotSupportedException:
UriTypeConverter cannot convert from (null).
Here is the initial code where the error occurs:
SlideViewModel s = new SlideViewModel() { Duration = 8 };
_slideList.Add(s);
SlideView = CollectionViewSource.GetDefaultView(_slideList);
SelectedSlide = s; //This is where it crashes
_slideList is an ObservableCollection of SlideViewModels. SelectedSlide is a SlideViewModel.
Going into the setter for the SelectedSlide property, the code is:
set
{
if (_selectedSlide != value)
{
_selectedSlide = value;
RaisePropertyChanged("SelectedSlide");
}
}
Going even further into the RaisePropertyChanged function:
protected void RaisePropertyChanged(String propertyName)
{
VerifyPropertyName(propertyName);
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
And then OnPropertyChanged:
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
var handler = this.PropertyChanged;
if (handler != null)
{
handler(this, e); //Crashes here!
}
}
No idea whats happening. There's no inner exception.
Upvotes: 1
Views: 1521
Reputation: 6316
You are ommiting you XAML
binding code, but from the type of error,
UriTypeConverter cannot convert from (null).
Here's a possibility.
If I am understanding correctly, SlideViewModel
is type of SlideViewModel, somewhere, you bind in XAML
to SlideViewModel
.
//something like this?
that some property on SlideViewModel
is probably a string.
Uri expects a type of Uri.
If that is correct, you need to create a converter that converts from Uri to String
The use it in binding like:
<SomeElement Uri="{Binding SlideViewModel.SomeProperty,
Converter={StaticResource MyUriToStringConverter}",.../>
If you are alreading using a converter, make sure it handle nulls.
Again, without xaml, or your target bindings, it is really hard to see who is responding to SlideViewModel
's PropertyChanged event.
Upvotes: 1