private static void BindSource(FImage img) { var value = img.Source; if (value.IsInvalid()) { return; } if (value.Length == 1) { img.FIcon.Text = value; return; } img.Dispatcher.BeginInvoke(new Action(() => { //创建一个image对象 var image = new Image() { Stretch = Stretch.Uniform }; image.Source = Util.Controls.ImageHelper.CreateImageSourceThumbnia(value, (int)img.Width, (int)img.Height); img.ContentBox.Child = image; }), DispatcherPriority.ApplicationIdle); }
private static void BindSource(FImage img) { var value = img.Source; if (value.IsInvalid()) { return; } if (value.Length == 1) { img.FIcon.Text = value; return; } img.Dispatcher.BeginInvoke(new Action(() => { var path = value.TrimStart(' ', '/', '\\'); //如果是相对路径则转换为绝对路径 if (!Path.IsPathRooted(path)) { path = File.GetPhysicalPath(path); } BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri(path); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); img.Image.Source = bitmapImage; }), DispatcherPriority.ApplicationIdle); }
/// <summary> /// 属性更改处理事件 /// </summary> private static void OnSourcePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { FImage img = sender as FImage; if (img == null) { return; } if (!img.IsLoaded) { return; } BindSource(img); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.uc = ((Util.Controls.FImage)(target)); return; case 2: this.Icon = ((System.Windows.Controls.TextBlock)(target)); return; case 3: this.img = ((System.Windows.Controls.Image)(target)); return; } this._contentLoaded = true; }