加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 仅在可见时延迟加载System.Windows.Control.Image

发布时间:2020-12-15 21:11:57 所属栏目:百科 来源:网络整理
导读:我需要我的应用程序仅在用户可见时才渲染图像.我试着附上.我试过以下(f#): image.IsVisibleChanged.Add(fun e - if image.IsVisible mtvCapture.Capture null then mtvCapture.BeginCapture() ) 但这只是加载,不会延迟加载. IsVisible如何工作,只有当用户将
我需要我的应用程序仅在用户可见时才渲染图像.我试着附上.我试过以下(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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读