ListViewに国旗のある国の一覧が表示されます。フラグは 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;
}
}
リストの非表示部分の 1 つまたは 2 つの画像が消えます。画像は、GeometryDrawing を使用して DrawingImage としてリソースに格納されます。別のページに移動してから戻ると、これらの画像が表示されますが、他の画像は表示されなくなる場合があります。デバッガーでは、これらの画像は ImageSource に固有のものであり、位置やサイズ変更などの画像パラメーターを変更すると、画像がすぐに表示されます。