我希望有一个Image
只有在首次显示时才会下载和显示。我希望CreateOptions.DelayCreation
有这种行为。事实上,我可以观察到它 延迟了图像的下载;但是,它实际上从未实现过。为什么呢?
这是我的代码:
<Window x:Class="WpfDelayCreationBug.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<BitmapImage x:Key="MySource"
UriSource="http://ihdwallpapers.com/download/minions-1920x1080.jpg"
CreateOptions="DelayCreation"
CacheOption="None"
/>
<BooleanToVisibilityConverter x:Key="Converter"/>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<CheckBox x:Name="Checkbox" Content="Display image" />
<Image Source="{StaticResource MySource}"
Grid.Row="1"
Visibility="{Binding ElementName=Checkbox, Path=IsChecked, Converter={StaticResource Converter}}"/>
</Grid>
</Window>
当我点击复选框时,我期待图像应该显示出来。它没有!如果我删除了CreateOptions="DelayCreation"
,那么当我选中此框时, 会显示图片。