I am currently using a custom Image object(a wrapper around <Image> object) in a listView. The properties of my custom Image object don't change when a new listview item is visible(realised).
For instance if my listview (containing 30 items with different image urls and different text) has 3 items on the first scroll then the 10th item has the same image as the 1st item. The images repeat in the order [1-9][1-9][1-9].... But to my surprise the text is different in all 30 listViewItems.
On debugging I found that the setter for my image object gets called only for the first 9 items. Can somebody shed light on how other system components(System Image/TextBlock working fine) get new element values?
Code snippet of relevant class property:
public sealed partial class CustomImage : UserControl
{
public static readonly DependencyProperty ImageSourceStringProperty = DependencyProperty.Register("ImageSourceString", typeof(string), typeof(CustomImage), new PropertyMetadata(null, new PropertyChangedCallback(ImageSourceStringChanged)));
public string ImageSourceString
{
get { return (string)GetValue(ImageSourceStringProperty); }
set
{
//THIS NEVER GETS HIT FOR ITEMS AFTER 9th ITEM
SetValue(ImageSourceStringProperty, value);
//{More code here}
}
}
}
Xaml Usage
<ListView ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<custom:customImage x:Name="Img" ImageSourceString="{Binding ImgPath}"/>
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Am I missing how it is supposed to work? In case something is not clear please let me know, I can clarify.