so I have a ListView with items. The DataTemplate contains a Rectangle. The Fill Brush is binded via a Converter which returns a new ImageBrush if the binded url is not null. If it is though the converter will return a Placeholder Brush:
public class StringImageBrushConverter : IValueConverter
{
readonly Brush placeholderBrush = new LinearGradientBrush([
new GradientStop() { Color = Color.FromArgb(144, 96, 96, 96), Offset = 0 },
new GradientStop() { Color = Color.FromArgb(10, 96, 96, 96), Offset = 1 },
], 45);
public object Convert(object value, Type targetType, object parameter, string language) =>
value is string imageUrl ? new ImageBrush() { ImageSource = new BitmapImage(new(imageUrl)) } : placeholderBrush;
public object ConvertBack(object value, Type targetType, object parameter, string language) =>
throw new NotImplementedException();
}
<DataTemplate x:DataType="plgm:SearchResult">
<Grid Padding="12">
<Rectangle
Width="50"
Height="50"
HorizontalAlignment="Left"
Fill="{x:Bind ImageUrl, Converter={StaticResource StringImageBrushConverter}}"
RadiusX="4"
RadiusY="4" />
<TextBlock
Margin="62,5,90,0"
Style="{StaticResource FlyoutPickerTitleTextBlockStyle}"
Text="{x:Bind Title}"
TextTrimming="CharacterEllipsis" />
<TextBlock
Margin="62,26,90,0"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="{x:Bind Artists}"
TextTrimming="CharacterEllipsis" />
<TextBlock
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="{x:Bind Duration, Converter={StaticResource TimeSpanStringConverter}}" />
</Grid>
</DataTemplate>
This works great – until navigating to a different page and then back to it. Then some images are completely gone (when scrolling they will appear since the Virtualization will recreate them). The behavior looks random to me, since its always different entries.
Here is what it looks like: