프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / Common / ImageAsyncHelper.cs @ c5519c44

이력 | 보기 | 이력해설 | 다운로드 (1.66 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Net;
5
using System.Text;
6
using System.Threading.Tasks;
7
using System.Windows;
8
using System.Windows.Data;
9

    
10
namespace KCOM.Common
11
{
12
    public class ImageAsyncHelper : DependencyObject
13
    {
14
        public static Uri GetSourceUri(DependencyObject obj) { return (Uri)obj.GetValue(SourceUriProperty); }
15
        public static void SetSourceUri(DependencyObject obj, Uri value) { obj.SetValue(SourceUriProperty, value); }
16

    
17
        public static readonly DependencyProperty SourceUriProperty = DependencyProperty.RegisterAttached("SourceUri", typeof(Uri), typeof(ImageAsyncHelper), new PropertyMetadata
18
        {
19
            PropertyChangedCallback = (obj, e) =>
20
            {
21
                //if (((System.Windows.Controls.Image)obj).Source == null)
22
                //{
23
                    System.Diagnostics.Debug.WriteLine(e.NewValue);
24

    
25
                    ((System.Windows.Controls.Image)obj).SetBinding(System.Windows.Controls.Image.SourceProperty,
26
                        new Binding("VerifiedUri")
27
                        {
28
                            Source = new ImageAsyncHelper { GivenUri = (Uri)e.NewValue },
29
                            IsAsync = true,
30
                        });
31
                //}
32
            }
33
        });
34

    
35
        Uri GivenUri;
36
        public Uri VerifiedUri
37
        {
38
            get
39
            {
40
                try
41
                {
42
                    //Dns.GetHostEntry(GivenUri.DnsSafeHost);
43
                    return GivenUri;
44
                }
45
                catch (Exception)
46
                {
47
                    return null;
48
                }
49

    
50
            }
51
        }
52
    }
53
}
클립보드 이미지 추가 (최대 크기: 500 MB)