0

In my XAML I have:

<Window.Resources>
   <DataTemplate x:Key="CastTemplate">
      <DockPanel Width="Auto">
          <Image Source="{Binding image}" Width="10" Height="10"/>
         <TextBlock Text="{Binding name}"/>
         <TextBlock Text="{Binding character}"/>
     </DockPanel>
  </DataTemplate>
<Window.Resources>

<Grid HorizontalAlignment="Center">
  <ItemsControl ItemTemplate="{StaticResource CastTemplate}" ItemsSource="{Binding SelectedItem.castInfoWithPics}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="3" Rows="2"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
  </ItemsControl>
</Grid>

The binding points to a list of objects with the following properties:

 public string name { get; set; }
 public string character { get; set; }
 public BitmapSource image { get; set; }

In my ViewModel, I assign the image property using:

cast.image = loadBitmap(bitmap);

I am using the loadBitmap function stated here: https://stackoverflow.com/a/1118557/2268507

The problem I'm having is that the image is not being displayed when I run my program. The name and character properties appear however.

I also don't seem to be receiving any Binding errors. Would anyone know what the issue might be?

Community
  • 1
  • 1
  • So, you probably used a debugger and that resulted in what? What did your function return? And another question: that method you use seems to have a very narrow use. Are you sure you are using it correctly. Why would you need it? – nvoigt Jan 26 '15 at 06:59
  • 2
    @Giri Can you specify when are you calling cast.image = loadBitmap(bitmap)? It might be that you are calling the function after your view has been initialized. If this is the case, you will need to implement INotifyPropertyChanged for your viewmodel to notify the view about the change in the image file. – Manar Husrieh Jan 26 '15 at 07:40

1 Answers1

1

are you sure you are using INotifyPropertyChangedin your View Model ? it looks like you are setting your other properties in the constructor and then setting your Bitmap property later on. in that case you must Raise the PropertyChanged Event .

stsur
  • 206
  • 2
  • 9
  • Ahh this was the issue.. I was assigning a `List` that had the above 3 properties. However, I was only assigning values to two of the properties initially. The `List` was a `Dependency Object`. Later on, I added the `image`. Thank you for your help. –  Jan 26 '15 at 09:47