0

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
DotNetRussell
  • 9,716
  • 10
  • 56
  • 111
  • put an empty set there – csharpwinphonexaml May 01 '14 at 20:12
  • Try dropping the leading `/` from your uri path. – Mike Strobel May 01 '14 at 20:19
  • Check [this question](http://stackoverflow.com/questions/2020374/a-first-chance-exception/2021164#2021164) out. A first chance exception isn't necessarily a bug in your code. You can set your debugger to only break on unhandled exceptions, and this will go away. [Also this.](http://blogs.msdn.com/b/davidklinems/archive/2005/07/12/438061.aspx) – Travis May 01 '14 at 20:34

1 Answers1

2

The answer ended up being that the path needed pack://application:,,,/Specific.Project.Name;component

Here is the link to the SO article that answered it

Image shows up in Visual Studio designer but not during run-time

Here is what the end result looked like

<image Source="pack://application:,,,/Specific.Project.Name;component/images/checked.png"/>

I was able to inject this into the binding as well and it works fine.

Community
  • 1
  • 1
DotNetRussell
  • 9,716
  • 10
  • 56
  • 111