microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.27k stars 674 forks source link

Proposal: Create IconSource from Bitmap stream #601

Open dotMorten opened 5 years ago

dotMorten commented 5 years ago

Proposal: Create IconSource from Bitmap stream

Summary

Currently we can only create IconSources from bitmaps on disk or Uri endpoing. There's no way to create IconSources from arbitrary streams (like embedded resources), or pulling from a URI that needs custom authentication.

Rationale

Porting Xamarin.Forms' Shell to UWP, I'm hit with this limitation where icons are packaged differently with the app, and there's no guarantee that an icon is available on disk. This means that in many scenarios the icons are rendered blank because there's no URI to map the resource to.

Functional Requirements

Syncronous instantiation to allow converters to return the correct type. Can be loading pixels on-demand and async if needed, with knowledge of the DPI required.

public class BitmapStreamIconSource : IconSource
{
   public BitmapStreamIconSource();
   protected Task<RandomAccessStream> GetStreamAsync(float scaleFactor);
}
jevansaks commented 5 years ago

@dotmorten is this blocking you from being able to adopt NavigationView in Xamarin? That would help inform the priority of this feature request.

dotMorten commented 5 years ago

@jevansaks It's blocking me from using icons for sure. I could switch to use image controls, but these icons are used in quite a lot of places, and would be the natural thing to use. It's forcing users who write xplat code to always use the same sort of xamarin.forms image (on-disk and packages with app as content), as all the other ones aren't possible, and thus rendering blank.

dotMorten commented 5 years ago

Here's the limitation in Xamarin.Forms: https://github.com/xamarin/Xamarin.Forms/blob/54b082198c7a367a037fe9f784feeed609b0aea5/Xamarin.Forms.Platform.UAP/FileImageSourcePathConverter.cs#L10

Only Forms' FileImageSource is able to convert to an IconSouce. All the other image sources are stream based.

YuliKl commented 5 years ago

Reassigning this request to @ryandemopoulos to help route to the best owner.

ryandemopoulos commented 5 years ago

Thanks @dotMorten . Our team is pretty heads-down with Build coming next week, but we'll take a look at this soon (probably later next week).

dotMorten commented 5 years ago

@ryandemopoulos Sounds good. I'll also be there all next week, if you want to chat face-to-face

groege commented 4 years ago

Just wanted to ask about the status of this issue => any idea if an when this will be done?