public override async void SetBackground(string imagePath, ContentStretch stretch) { System.Windows.Media.ImageBrush brush = null; BitmapImage bitmap = null; if (!string.IsNullOrWhiteSpace(imagePath)) { bitmap = await WpfFactory.LoadBitmapAsync(imagePath); brush = new System.Windows.Media.ImageBrush(bitmap); } if (brush == null || bitmap == null) { backCanvas.Background = null; backCanvas.Height = double.NaN; backCanvas.Width = double.NaN; } else { brush.Stretch = (System.Windows.Media.Stretch)stretch; backCanvas.Background = brush; backCanvas.Height = bitmap.Height; backCanvas.Width = bitmap.Width; } }
public async static Task <ImageBrush> GetImageBrush(this string uri) { if (string.IsNullOrWhiteSpace(uri)) { return(null); } return(new ImageBrush(await WpfFactory.LoadBitmapAsync(uri))); }
private async void SetSource(string uri) { var imageData = uri == null ? null : Device.ImageCache.Get(uri); if (imageData != null && (creationOptions & ImageCreationOptions.IgnoreCache) != 0) { Device.ImageCache.Remove(uri); imageData = null; } BitmapImage source = null; if (imageData == null) { if (uri != null && (uri.StartsWith("http") || uri.StartsWith("ftp"))) { source = new BitmapImage(new Uri(uri), new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache)); } else { source = await WpfFactory.LoadBitmapAsync(uri); } if (source != null) { source.DownloadCompleted -= OnDownloadCompleted; source.DownloadCompleted += OnDownloadCompleted; if ((creationOptions & ImageCreationOptions.IgnoreCache) == 0) { Device.ImageCache.Add(uri, new ImageData(source)); } } } else { var data = imageData as ImageData; source = data == null ? null : data.Source; } image.Source = source; var handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs("Dimensions")); } var parent = this.GetParent <IPairable>() as FrameworkElement; if (parent != null) { parent.InvalidateMeasure(); } }
private async void SetImage(string uri) { var grid = Content as System.Windows.Controls.Grid; if (grid != null) { if (grid.Children.Count > 1) { grid.Children.RemoveAt(1); } grid.Children.Insert(1, new System.Windows.Controls.Image() { Source = await WpfFactory.LoadBitmapAsync(uri) }); } }
public async void Load(string fileName) { //if the first child is an image, that means something else was loaded and it should be cleared if (inkCanvas.Children.Count > 0 && inkCanvas.Children[0] is System.Windows.Controls.Image) { inkCanvas.Children.RemoveAt(0); } if (!string.IsNullOrWhiteSpace(fileName)) { var image = new System.Windows.Controls.Image() { Source = await WpfFactory.LoadBitmapAsync(fileName), Stretch = System.Windows.Media.Stretch.None, }; inkCanvas.Children.Insert(0, image); } }
private static async void OnSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { var inlineImage = (InlineImage)sender; var bitmapImage = await WpfFactory.LoadBitmapAsync(inlineImage.Source); if (bitmapImage == null) { inlineImage.Height = new FigureLength(0); inlineImage.Width = new FigureLength(0); inlineImage.Margin = new Thickness(0); inlineImage.Padding = new Thickness(0); return; } var setImage = new Action <object, EventArgs>((ob, ev) => { var image = new System.Windows.Controls.Image { Source = bitmapImage, Stretch = Stretch.Uniform, StretchDirection = StretchDirection.Both, Margin = new Thickness(0), MaxHeight = inlineImage.Height.IsAuto ? bitmapImage.PixelHeight : inlineImage.Height.Value, MaxWidth = inlineImage.Width.IsAuto ? bitmapImage.PixelWidth : inlineImage.Width.Value, }; inlineImage.Width = new FigureLength(image.MaxWidth, FigureUnitType.Pixel); inlineImage.Blocks.Clear(); inlineImage.Blocks.Add(new BlockUIContainer { Child = image, Padding = new Thickness(0), Margin = new Thickness(0), }); inlineImage.ToolTip = inlineImage.ToolTip; }); if (bitmapImage.IsDownloading) { bitmapImage.DownloadCompleted += (ob, ev) => setImage(ob, ev); } else { setImage(bitmapImage, EventArgs.Empty); } }
public static async void SkinLayer(this FrameworkElement control, Style style) { control.SetBinding(Control.ForegroundProperty, new Binding("TextColor") { Source = style, Converter = ColorConverter }); if (string.IsNullOrWhiteSpace(style.LayerBackgroundImage)) { control.SetBinding(Control.BackgroundProperty, new Binding("LayerBackgroundColor") { Source = style, Converter = ColorConverter, }); } else { control.SetValue(Control.BackgroundProperty, new ImageBrush { ImageSource = await WpfFactory.LoadBitmapAsync(style.LayerBackgroundImage), Stretch = Stretch.UniformToFill, }); } }
private async void SetImage(string uri) { Content = new System.Windows.Controls.Image() { Source = await WpfFactory.LoadBitmapAsync(uri) }; if (!HasImage) { if (title == null) { Content = "\uE600"; FontFamily = new System.Windows.Media.FontFamily(new Uri("pack://application:,,,/iFactr.Wpf;component/"), "./Resources/#WPF-Symbol"); FontSize = 20; } else { Content = title; FontFamily = new System.Windows.Media.FontFamily("Segoe UI"); FontSize = 12; } } }
private async void SetSource(string uri) { image.Source = await WpfFactory.LoadBitmapAsync(uri); }