示例#1
0
        /// <summary>
        /// 文件大小改变时,赋值到TextBlock
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        private static void OnFileSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            AsyncVideoControl imageControl = (AsyncVideoControl)d;

            if (e.NewValue != null)
            {
                imageControl.BorderFileSize.Visibility = Visibility.Visible;
                imageControl.txtFilesize.Text          = (string)e.NewValue;
            }
            else
            {
                imageControl.BorderFileSize.Visibility = Visibility.Collapsed;
            }
        }
示例#2
0
        /// <summary>
        /// 消息改变时
        /// </summary>
        /// <param name="d">母控件</param>
        /// <param name="e">更改相关值</param>
        private static void OnBubbleMsgChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            AsyncVideoControl imagecontrol = (AsyncVideoControl)d;

            if (e.NewValue != null)
            {
                #region Download Image File
                string uri = (string)e.NewValue;
                if (uri.Contains("http"))//if it's Web url
                {
                    //get info about the path
                    string localpath        = Applicate.LocalConfigData.ChatDownloadPath;
                    ChatBubbleItemModel msg = imagecontrol.Tag as ChatBubbleItemModel;
                    if (msg.fileName == null)
                    {
                        return;
                    }
                    string filename = msg.fileName.Substring(
                        msg.fileName.LastIndexOf('/') + 1,
                        msg.fileName.Length - msg.fileName.LastIndexOf('/') - 1
                        );
                    var localfile = localpath + filename;
                    if (File.Exists(localfile))//if file exists, fill the image of the border
                    {
                        var         imguri   = new Uri(localfile);
                        BitmapImage mapImage = ImageUtil.ConvertBitmapToBitmapImage(WindowsThumbnailProvider.GetThumbnail(localfile, 256, 256, ThumbnailOptions.None));
                        imagecontrol.Imgborder.Background       = new ImageBrush(mapImage);
                        imagecontrol.transitioner.SelectedIndex = 1;
                    }
                    else//if not exists
                    {
                        try
                        {
                            WebClient web = new WebClient();
                            //when the progress changed , set the value of the progressbar
                            web.DownloadProgressChanged += (s, ev) =>
                            {
                                imagecontrol.ImageProgress.Value = ev.ProgressPercentage;
                            };
                            //When download completed, fill the image of the border
                            web.DownloadFileCompleted += (s, ev) =>
                            {
                                if (ev.Error == null)
                                {
                                    BitmapImage mapImage = ImageUtil.ConvertBitmapToBitmapImage(WindowsThumbnailProvider.GetThumbnail(localfile, 256, 256, ThumbnailOptions.None));
                                    imagecontrol.Imgborder.Background       = new ImageBrush(mapImage);
                                    imagecontrol.transitioner.SelectedIndex = 1;
                                    //Set Border Background(Not for now)
                                    //var imguri = new Uri(localfile);
                                    //imagecontrol.Imgborder.Background = new ImageBrush(new BitmapImage(imguri));
                                    web.Dispose();// Dispose the WebClient
                                }
                                else
                                {
                                    ConsoleLog.Output("视频下载失败");
                                }
                            };
                            //Start download image async
                            web.DownloadFileAsync(new Uri(uri), localfile);
                        }
                        catch (Exception ex)
                        {
                            ConsoleLog.Output("Download Aaudio Error:;;", ex);
                        }
                        #endregion
                    }
                }
                else//if it's local path
                {
                    if (File.Exists(uri))
                    {
                        BitmapImage mapImage = ImageUtil.ConvertBitmapToBitmapImage(WindowsThumbnailProvider.GetThumbnail(uri, 256, 256, ThumbnailOptions.None));
                        imagecontrol.Imgborder.Background       = new ImageBrush(mapImage);
                        imagecontrol.transitioner.SelectedIndex = 1;
                    }
                }
            }
            else
            {
                return;
            }
        }