我在silverlight for windows phone中有以下代码:
<Border CornerRadius="0" x:Name="brdTest" BorderBrush="Black" BorderThickness="4" Width="100" Height="60">
<Border.Background>
<ImageBrush x:Name="backgroundImageBrush" Stretch="Fill">
<ImageBrush.ImageSource>
<BitmapImage x:Name="bmpBackground" UriSource="http://www.images.com/1.jpg">
</BitmapImage>
</ImageBrush.ImageSource>
</ImageBrush>
</Border.Background>
</Border>当图像(http://www.images.com/1.jpg)加载并在图像加载时,如何从silverlight工具包中添加加载活动指示器?
图像是否加载在后台线程中?还是他们阻止了主UI线程?(也就是说,我想在许多列表框项目的模板中使用此方法)
我尝试了这段代码并加载了一个大图片(70MP),当图像加载时,应用程序的主UI线程没有冻结
发布于 2011-10-18 13:41:13
您可以使用ProgressOverlay或PerformanceProgressBar。下面是一个使用ProgressOverlay的示例
<Grid>
<Border CornerRadius="0" x:Name="brdTest" BorderBrush="Black" BorderThickness="4" Width="400" Height="360">
<Border.Background>
<ImageBrush x:Name="backgroundImageBrush" Stretch="Fill">
<ImageBrush.ImageSource>
<BitmapImage x:Name="bmpBackground"
UriSource="http://www.bestmotherofthegroomspeeches.com/wp-content/themes/thesis/rotator/sample-4.jpg"
ImageOpened="bmpBackground_ImageOpened">
</BitmapImage>
</ImageBrush.ImageSource>
</ImageBrush>
</Border.Background>
</Border>
<Controls:ProgressOverlay
x:Name="overlay"
Width="400" Height="360">
<Controls:ProgressOverlay.Content>
<StackPanel>
<TextBlock HorizontalAlignment="Center">Loading Image</TextBlock>
<toolkit:PerformanceProgressBar IsIndeterminate="True"/>
</StackPanel>
</Controls:ProgressOverlay.Content>
</Controls:ProgressOverlay>
</Grid>在bmpBackground_ImageOpened事件处理程序中,添加隐藏OverlayProgress的overlay.Hide();。
这种方法似乎比仅仅使用PerformanceProgressBar更好,因为它为用户提供了一个关于正在发生的事情的指示。
PS:OverlayProgress没有正常工作,直到我在它的“内容”中添加了一个PerformanceProgressBar,如代码所示。(试着移除它,看看它是否适合你)。
我希望这有帮助:)
发布于 2011-10-18 10:36:17
检查此链接。在这里,作者解释了进度指示符,并使用不同的线程使用Dispatcher.BeginInvoke,您可以切换进度栏的可见性,并显示图像。希望这能有所帮助。
发布于 2011-10-18 13:09:52
刚刚添加到BitmapImage : ImageOpened="bmpBackground_ImageOpened“中,这将调用一个方法,以便我可以删除一个子(工具包加载项)。
编辑
如何调用包含名为"bmpBackground_ImageOpened“的图像的列表框来删除子列表?实际上,我想调用这个spacific的父BitmapImage,这样我就可以删除一个子BitmapImage(加载图像)。
https://stackoverflow.com/questions/7805070
复制相似问题