A list of countries with flags is displayed in ListView. Flags are displayed as an ellipse with Fill ImageBrush.
<ControlTemplate TargetType="ContentControl">
<StackPanel Orientation="Horizontal" Background="Transparent">
<Ellipse Width="23" Height="23" StrokeThickness="1" Stroke="#2F7AE5" Fill="{Binding FlagBrush}"/>
<TextBlock Text="{Binding Path=Country}"
Foreground="{StaticResource HBBtnTextBrush}" FontSize="16" FontWeight="Bold"
VerticalAlignment="Center" Margin="14,0,0,0"/>
<ContentPresenter/>
</StackPanel>
</ControlTemplate>
public ImageSource FlagImage { get => Flag.GetImage(country_code); }
ImageBrush flagBrush;
public ImageBrush FlagBrush {
get
{
if (flagBrush == null)
{
flagBrush = new ImageBrush
{
ImageSource = FlagImage,
Stretch = Stretch.UniformToFill
};
flagBrush.Freeze();
}
return flagBrush;
}
}
One or two images in the hidden part of the list disappear. Images are stored in resources as DrawingImage with GeometryDrawing. If you go to another page and then return these images will appear, but others may disappear. In the debugger, these images are inherent in ImageSource, and if you change any image parameter, for example, position or resize, the image immediately appears.