-
Notifications
You must be signed in to change notification settings - Fork 1.9k
UWP IconImageSource from netstandard 2.0 #6534
Comments
Hallo @jfversluis, At the moment the alternative is, to copy all the images to the UWP project, which will produce redundancy of image files. |
After investigation, I found out the error can be caused, because the |
Hi @jonkas2211 unfortunately I do not have any estimation for you, sorry about that. Since you have been investigating we are of course more than happy to see a pull request that fixes this issue. Have you actually verified that this is the problem? |
Hello @jfversluis, The Method public static async Task<IconElement> ToWindowsIconElementAsync(this ImageSource source, CancellationToken cancellationToken = default(CancellationToken))
{
if (source == null || source.IsEmpty)
return null;
var handler = Registrar.Registered.GetHandlerForObject<IIconElementHandler>(source);
if (handler == null)
return null;
try
{
return await handler.LoadIconElementAsync(source, cancellationToken);
}
catch (OperationCanceledException)
{
// no-op
}
return null;
} Is looking for the handler to implement I would love to create a pull request, but unfortunately I am no UWP expert and I dont know how to conver a Stream to a IconElement. I surely could save the Stream as a kind of image to the disk and relead it from an uri, but this is not how it supposed be? |
It might be a limitation of UWP |
From what I can see this is simply not implemented in UWP indeed. The original implementation is from @mattleibow maybe he can shine his light on this? I have been looking into it a little bit and the only possibility I see right now is to save the stream to a (temp) location and then load the images from there, but that doesn’t seem ideal as well. So then yes, it is a limitation on UWP. |
Just spitballing here, but we might be able to do something with a bitmap that is a brush and use the brush. I see this was also added in a later version of UWP: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.iconsourceelement We might be able to do some things if we get a little bit creative. |
That seems to be a plan, but how would we handle targeting Windows 10, version 1809 (introduced v10.0.17763.0)? |
It might be possible to use multitargeting to generate separate dlls so we can still support a desired target framework. But, the thing to do would be to bump the target version to the highest, but keep the minimum at the lowest. Then, use the |
For reference look at this Issue on the Microsoft microsoft-ui-xaml repository: microsoft/microsoft-ui-xaml#601 |
So I tried to create a brush an set the Foreground from the IconElement, but it seems to end in a silent exception: public async Task<IconElement> LoadIconElementAsync(ImageSource imagesource, CancellationToken cancellationToken = new CancellationToken())
{
IconElement image = null;
if (imagesource is StreamImageSource streamSource)
{
image = new BitmapIcon();
var brush = new ImageBrush();
using (Stream stream = await((IStreamImageSource)streamSource).GetStreamAsync(cancellationToken))
{
if (stream == null)
return null;
var source = new BitmapImage();
await source.SetSourceAsync(stream.AsRandomAccessStream());
brush.ImageSource = source;
image.SetForeground(brush); // throws silent Argument Exception seen in output
}
}
return image;
} |
If you wrap the code in a try catch, is it possible to see what it is? Maybe the async is causing the silence. |
Thanks @mattleibow if things could always be easy as that. |
Thanks for letting us know! Closing this one then |
Description
If you want to add your images in to the netstandard project and trie to add them in as a IconImageSource for a ToolbarItem then it does not appear on UWP.
On Android it will appear as shown in the screenshot.
If you add the image as an Image view inside your layout it will just work fine, so the ImageSource is not the problem.
Steps to Reproduce
var imageSource = ImageSource.FromResource("UWPToolbarItemsImageBug.Images.test.png", typeof(App).Assembly);
ToolbarItem
and set theIconImageSource
propertyExpected Behavior
Image should be shown in the toolbar.
Actual Behavior
Image does not appear in the toolbar on UWP
Basic Information
Screenshots
Reproduction Link
UWPToolbarItemsImageBug.zip
The text was updated successfully, but these errors were encountered: