Esempio n. 1
0
 /// <summary>
 /// 载入网站Icon
 /// </summary>
 /// <param name="url"></param>
 public async void LoadIcon(string url)
 {
     await System.Threading.Tasks.Task.Run(() =>
     {
         try
         {
             var source   = TaskHelper.GetDomain(url, true) + "/favicon.ico";
             WebClient wb = new WebClient();
             byte[] data  = wb.DownloadData(source);
             if (data == null || data.Count() < 10)
             {
                 return;
             }
             App.Current.Dispatcher.BeginInvoke(new Action <MemoryStream>(od =>
             {
                 try
                 {
                     var b = new BitmapImage();
                     b.BeginInit();
                     b.CacheOption  = BitmapCacheOption.OnLoad;
                     b.StreamSource = od;
                     b.EndInit();
                     b.Freeze();
                     ChrominViewModel target = null;
                     if (refrence != null)
                     {
                         refrence.TryGetTarget(out target);
                     }
                     if (target != null)
                     {
                         target.Icon = b;
                     }
                 }catch (Exception er)
                 {
                     Console.WriteLine(" 创建faveicon 失败 : " + er.Message);
                 }
             }), new MemoryStream(data));
         }
         catch (Exception) { Console.WriteLine(string.Format(" 获取网络资源[{0}/favicon.ico]失败 : ", url)); }
     });
 }
Esempio n. 2
0
 public CustomLoadHandler(ChrominViewModel cvm)
 {
     refrence = new WeakReference <ChrominViewModel>(cvm);
 }