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(() => { try { 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; } catch { } }), 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 = ((ScriptPlugin.Theme.Control.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; }