我需要我的应用程序仅在用户可见时才渲染图像.我试着附上.我试过以下(f#):
image.IsVisibleChanged.Add(fun e -> if image.IsVisible & mtvCapture.Capture <> null then mtvCapture.BeginCapture() )
但这只是加载,不会延迟加载. IsVisible如何工作,只有当用户将图像元素滚动到视图中时才会这样?
还尝试修改绑定源,如下所示:
public ImageSource ImageElementSource { get { if (Capture == null) { BeginCapture(); return loadingImageSource; } CapturetoWpfImage(); return imageElement.source; } }
只有当图像滚动到视图中时,才能调用BeginCapture()?
解决方法
听起来你需要一些支持虚拟化的东西.这仅在加载时创建可见元素.所有其他元素在可见时都会变得懒惰.
使用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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。