Silverlight loading large image progress prompt

Source: Internet
Author: User

When using large images in Silverlight, loading may be slow and the progress is displayed.

1. Create a user control lodingimage. XAML

The XAML is as follows:

 

Code

 <Grid X: Name = "layoutroot" background = "white">
<Image X: Name = "IMG"/>
<Image Source = "default.png" X: Name = "imgback"/>
<Textblock text = "loading 85%" X: Name = "txtloading" horizontalalignment = "center" foreground = "yellow" verticalalignment = "center"/>
</GRID>

 

CS is as follows:

 

Code

 1 using system;
2 using system. Collections. Generic;
3 using system. LINQ;
4 using system. net;
5 using system. windows;
6 using system. Windows. controls;
7 using system. Windows. documents;
8 using system. Windows. input;
9 using system. Windows. Media;
10 using system. Windows. Media. animation;
11 using system. Windows. shapes;
12 using system. Windows. Media. imaging;
13
14 namespace webimage
15 {
16 public partial class lodingimage: usercontrol
17 {
18 /// <summary>
19 // image address
20 /// </Summary>
21 Public String URI {Get; set ;}
22 public stretch imagestretch
23 {
24 get {return IMG. Stretch ;}
25 set {IMG. Stretch = value ;}
26}
27
28 bitmapimage;
29
30 public lodingimage ()
31 {
32 initializecomponent ();
33 this. Loaded + = new routedeventhandler (lodingimage_loaded );
34}
35
36 void lodingimage_loaded (Object sender, routedeventargs E)
37 {
38 bitmapimage = new bitmapimage ();
39 IMG. Source = bitmapimage;
40 bitmapimage. urisource = new uri (URI );
41 IMG. Stretch = stretch. Fill;
42 bitmapimage. downloadprogress + = new eventhandler <downloadprogresseventargs> (img_downloadprogress );
43 bitmapimage. imagefailed + = new eventhandler <exceptionroutedeventargs> (img_imagefailed );
44 bitmapimage. imageopened + = new eventhandler <routedeventargs> (img_imageopened );
45
46}
47
48 void reload ()
49 {
50 bitmapimage = new bitmapimage ();
51}
52
53 void img_imageopened (Object sender, routedeventargs E)
54 {
55 imgback. Visibility = txtloading. Visibility = system. Windows. Visibility. collapsed;
56
57}
58
59 void img_imagefailed (Object sender, exceptionroutedeventargs E)
60 {
61 txtloading. Text = string. Format ("loading failed ");
62}
63
64 void img_downloadprogress (Object sender, downloadprogresseventargs E)
65 {
66 txtloading. Text = string. Format ("loading {0} %", E. Progress );
67}
68}
69}
70

 

 

2. The call is as follows:

<Wimage: lodingimage uri = "http: // 192.168.23.small: 88/image/big.jpg "width =" 350 "Height =" 280 "horizontalalignment =" Left "imagestretch =" Uniform "/>

Based on the practices of this student

Http://www.cnblogs.com/struggle-luan/archive/2009/01/04/1368471.html

Source code download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.