我需要我的应用程序仅在图像对用户可见时才呈现图像。我试着附上。我尝试了以下 (f#):
image.IsVisibleChanged.Add(fun e ->
if image.IsVisible & mtvCapture.Capture <> null then
mtvCapture.BeginCapture()
)
但这只是加载,而不是延迟加载。 IsVisible 是如何工作的,只有当用户将图像元素滚动到 View 中时才会出现这种情况吗?
还尝试像这样修改绑定(bind)源:
public ImageSource ImageElementSource
{
get
{
if (Capture == null)
{
BeginCapture();
return loadingImageSource;
}
CaptureToWpfImage();
return imageElement.Source;
}
}
如何才能让 BeginCapture() 只有在图像滚动到 View 中时才被调用?
最佳答案
听起来您需要支持虚拟化的东西。这只会在加载时创建可见元素。所有其他元素在可见时都是惰性创建的。
将 VirtualizingStackPanel 用于 ListBox 的示例
<ListBox Name="c_imageListBox">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding ImagePath}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
关于c# - 仅在可见时延迟加载 System.Windows.Control.Image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4033741/