加载完成后运行一个函数 [英] run a function after loading is done

查看:94
本文介绍了加载完成后运行一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有这个代码:

hi all

i have this code:

<pre lang="vb">Dim tester As New BitmapImage<br />
        Dim imgplate As String = "approot.test.png"<br />
        Dim Strm As Stream = Me.GetType().Assembly.GetManifestResourceStream(imgplate)<br />
        tester.BeginInit()<br />
        tester.StreamSource = Strm<br />
        tester.EndInit()<br />
        imgPreview.Source = tester<br />
</pre><br />


从嵌入式资源加载图像,如果我从button_click事件调用它,它将起作用,但是如果我从slider_valuechanged事件调用,它将给我这个错误:


to load an image from an embedded resource and it works will if i called it from a button_click event, but if i called it from a slider_valuechanged event it will give me this error:

Property ''UriSource'' or property ''StreamSource'' must be set


在imgpreview.source

所以我认为滑块是在嵌入资源之前加载的??,如果是,我该如何解决,欢迎您提出任何想法:)


on the imgpreview.source

so i think that the slider is loaded before the embedded resource??, if yes how can i work around that, any ideas will be welcome :)

推荐答案

我的第一个问题是当可以快速连续触发该事件时,为什么要在该值更改的事件中加载图像?我要么尽可能预加载图像,要么将Bitmap对象加载到后台线程.

在您的代码调用之前,资源不会加载或执行任何操作.仅仅是数据.
My first question is why you''re loading an image in the value changed event when that event can be fired in rapid succession? I''d either preload the images as much as possible or farm out loading Bitmap objects to a background thread.

Resources don''t load or do anything until your code calls on them. It''s just data.


我的第一个问题是,当可以快速连续触发该值更改的事件时,为什么要在该事件中加载图像?小>
因为我要滚动浏览我拥有的图像,并且想一次上传一个,因为我的应用程序正在处理很多图像,所以我无法预加载它们.

关于您提到的后台操作将解决此问题,如果可以,您可以共享文档.或有关它的链接?
My first question is why you''re loading an image in the value changed event when that event can be fired in rapid succession?
because i want to scroll over the images that i have and i want to upload one at a time as my app is going through a lot of them, i just can''t preload them.

about the background operation you mentioned will that solve the problem, if yes can you share a doc. or a link about it?


好,我想听听我的声音,反正我用两个下一个和上一个按钮替换了滑块.
OK i''m pulling my hear, anyway i replaced the slider with two next and previous buttons.


这篇关于加载完成后运行一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆