I have other bindings in this viewmodel working fine. I am not sure why this one isn't though. I have tried a number of different ways to update the image source with binding. All have failed. This is the most common way I have seen and this is the way I have done it on the Windows Phone. I am not sure why this isn't working in WPF.
The XAML
<ComboBox
ItemsSource="{Binding Keywords}"
SelectedItem="{Binding SelectedKeyword, Mode=TwoWay}">
<ComboBox.ItemTemplate>
<DataTemplate>
<Label Width="280" Content="{Binding KeywordName}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Grid>
<Image Source="{Binding LinkedImage}"/>
</Grid>
The viewmodel
public KeywordObject SelectedKeyword
{
get { return _SelectedKeyword; }
set { _SelectedKeyword = value; OnPropertyChanged("LinkedImage"); }
}
public Boolean _IsLinked
{
get { return _SelectedKeyword.KeywordNumber.Length > 0; }
}
public ImageSource LinkedImage
{
get
{
return _IsLinked ?
new BitmapImage(new Uri("/images/checked.png", UriKind.RelativeOrAbsolute))
:
new BitmapImage(new Uri("/images/unchecked.png", UriKind.RelativeOrAbsolute));
}
}
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string prop)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(prop));
}
}
This is the exception that is outputted in the debuger
A first chance exception of type 'System.IO.IOException' occurred in PresentationFramework.dll
A first chance exception of type 'System.IO.IOException' occurred in PresentationCore.dll