private BitmapIconSource MakeBitmapIcon() { BitmapIconSource iconSource = new BitmapIconSource(); iconSource.ShowAsMonochrome = false; Uri uri = new Uri("ms-appx:/Assets/ingredient1.png"); iconSource.UriSource = uri; iconSource.Foreground = iconForegroundBrush; return(iconSource); }
public Task <Microsoft.UI.Xaml.Controls.IconSource> LoadIconSourceAsync(ImageSource imagesource, CancellationToken cancellationToken = default) { var imageLoader = imagesource as UriImageSource; if (imageLoader?.Uri == null) { return(null); } Microsoft.UI.Xaml.Controls.IconSource image = new Microsoft.UI.Xaml.Controls.BitmapIconSource { UriSource = imageLoader?.Uri }; return(Task.FromResult(image)); }
public Task <Microsoft.UI.Xaml.Controls.IconSource> LoadIconSourceAsync(ImageSource imagesource, CancellationToken cancellationToken = default(CancellationToken)) { Microsoft.UI.Xaml.Controls.IconSource image = null; if (imagesource is FileImageSource filesource) { UpdateImageDirectory(filesource); string file = filesource.File; image = new Microsoft.UI.Xaml.Controls.BitmapIconSource { UriSource = new Uri("ms-appx:///" + file) }; } return(Task.FromResult(image)); }
public void BitmapIconSourceTest() { BitmapIconSource iconSource = null; BitmapIcon bitmapIcon = null; var uri = new Uri("ms-appx:///Assets/ingredient1.png"); RunOnUIThread.Execute(() => { iconSource = new BitmapIconSource(); bitmapIcon = iconSource.CreateIconElement() as BitmapIcon; // IconSource.Foreground should be null to allow foreground inheritance from // the parent to work. Verify.AreEqual(iconSource.Foreground, null); //Verify.AreEqual(bitmapIcon.Foreground, null); Log.Comment("Validate the defaults match BitmapIcon."); var icon = new BitmapIcon(); Verify.AreEqual(icon.UriSource, iconSource.UriSource); Verify.AreEqual(bitmapIcon.UriSource, iconSource.UriSource); if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.BitmapIcon", "ShowAsMonochrome")) { Verify.AreEqual(icon.ShowAsMonochrome, iconSource.ShowAsMonochrome); Verify.AreEqual(bitmapIcon.ShowAsMonochrome, iconSource.ShowAsMonochrome); } Log.Comment("Validate that you can change the properties."); iconSource.Foreground = new SolidColorBrush(Windows.UI.Colors.Red); iconSource.UriSource = uri; iconSource.ShowAsMonochrome = false; }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { Verify.IsTrue(iconSource.Foreground is SolidColorBrush); Verify.IsTrue(bitmapIcon.Foreground is SolidColorBrush); Verify.AreEqual(Windows.UI.Colors.Red, (iconSource.Foreground as SolidColorBrush).Color); Verify.AreEqual(Windows.UI.Colors.Red, (bitmapIcon.Foreground as SolidColorBrush).Color); Verify.AreEqual(uri, iconSource.UriSource); Verify.AreEqual(uri, bitmapIcon.UriSource); Verify.AreEqual(false, iconSource.ShowAsMonochrome); Verify.AreEqual(false, bitmapIcon.ShowAsMonochrome); }); }
public void InfoBadgeSupportsAllIconTypes() { InfoBadge infoBadge = null; SymbolIconSource symbolIconSource = null; PathIconSource pathIconSource = null; AnimatedIconSource animatedIconSource = null; BitmapIconSource bitmapIconSource = null; ImageIconSource imageIconSource = null; FontIconSource fontIconSource = null; RunOnUIThread.Execute(() => { infoBadge = new InfoBadge(); symbolIconSource = new SymbolIconSource(); symbolIconSource.Symbol = Symbol.Setting; fontIconSource = new FontIconSource(); fontIconSource.Glyph = "99+"; fontIconSource.FontFamily = new FontFamily("XamlAutoFontFamily"); bitmapIconSource = new BitmapIconSource(); bitmapIconSource.ShowAsMonochrome = false; Uri bitmapUri = new Uri("ms-appx:/Assets/ingredient1.png"); bitmapIconSource.UriSource = bitmapUri; imageIconSource = new ImageIconSource(); var imageUri = new Uri("https://raw.githubusercontent.com/DiemenDesign/LibreICONS/master/svg-color/libre-camera-panorama.svg"); imageIconSource.ImageSource = new SvgImageSource(imageUri); pathIconSource = new PathIconSource(); var geometry = new RectangleGeometry(); geometry.Rect = new Windows.Foundation.Rect { Width = 5, Height = 2, X = 0, Y = 0 }; pathIconSource.Data = geometry; animatedIconSource = new AnimatedIconSource(); animatedIconSource.Source = new AnimatedSettingsVisualSource(); Content = infoBadge; Content.UpdateLayout(); }); IdleSynchronizer.Wait(); RunOnUIThread.Execute(() => { Log.Comment("Switch to Symbol Icon"); infoBadge.IconSource = symbolIconSource; Content.UpdateLayout(); Log.Comment("Switch to Path Icon"); infoBadge.IconSource = pathIconSource; Content.UpdateLayout(); Log.Comment("Switch to Font Icon"); infoBadge.IconSource = fontIconSource; Content.UpdateLayout(); Log.Comment("Switch to bitmap Icon"); infoBadge.IconSource = bitmapIconSource; Content.UpdateLayout(); Log.Comment("Switch to Image Icon"); infoBadge.IconSource = imageIconSource; Content.UpdateLayout(); Log.Comment("Switch to Animated Icon"); infoBadge.IconSource = animatedIconSource; Content.UpdateLayout(); }); }