Lazy loading System.Windows.Control.Image only when visible

I need my application to render an image only when it becomes visible to the user. I tried to install. I tried the following (f #):

   image.IsVisibleChanged.Add(fun e ->
        if image.IsVisible & mtvCapture.Capture <> null then
            mtvCapture.BeginCapture()
        )

But it just loads, not lazy loading. How IsVisible works, is it only true when users scroll an image element in the field of view?

Also tried to change the binding source as follows:

    public ImageSource ImageElementSource
    {
        get
        {
            if (Capture == null)
            {
                BeginCapture();
                return loadingImageSource;
            }

            CaptureToWpfImage();
            return imageElement.Source;
        }
    }

How can I call BeginCapture () only when scrolling an image in a view?

+3
source share
1 answer

, -, . . , .

VirtualizationStackPanel 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>
+1

Source: https://habr.com/ru/post/1771726/


All Articles