зеркало из https://github.com/DeGsoft/maui-linux.git
[UWP] Fixes the casting crash of the FontImageSource (#5678)
This commit is contained in:
Родитель
421c4f21d7
Коммит
efd55b8b3f
|
@ -31,7 +31,17 @@ namespace Xamarin.Forms.Controls
|
|||
break;
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
grid.Children.Add(new ImageButton
|
||||
{
|
||||
Source = new FontImageSource
|
||||
{
|
||||
Glyph = Ionicons[Ionicons.Length - 1].ToString(),
|
||||
FontFamily = fontFamily,
|
||||
Size = 20
|
||||
},
|
||||
});
|
||||
|
||||
var i = 1;
|
||||
foreach (char c in Ionicons)
|
||||
{
|
||||
grid.Children.Add(new Image
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using Microsoft.Graphics.Canvas.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
using WinImageSource = Windows.UI.Xaml.Media.ImageSource;
|
||||
|
||||
namespace Xamarin.Forms.Platform.UWP
|
||||
{
|
||||
internal static class ImageExtensions
|
||||
{
|
||||
public static SizeRequest GetDesiredSize(this WinImageSource source)
|
||||
{
|
||||
if (source is BitmapSource bitmap)
|
||||
{
|
||||
return new SizeRequest(
|
||||
new Size
|
||||
{
|
||||
Width = bitmap.PixelWidth,
|
||||
Height = bitmap.PixelHeight
|
||||
});
|
||||
}
|
||||
else if (source is CanvasImageSource canvas)
|
||||
{
|
||||
return new SizeRequest(
|
||||
new Size
|
||||
{
|
||||
Width = canvas.SizeInPixels.Width,
|
||||
Height = canvas.SizeInPixels.Height
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidCastException($"\"{source.GetType().FullName}\" is not supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -54,14 +54,7 @@ namespace Xamarin.Forms.Platform.UWP
|
|||
|
||||
_measured = true;
|
||||
|
||||
|
||||
var result = new Size
|
||||
{
|
||||
Width = ((BitmapSource)_image.Source).PixelWidth,
|
||||
Height = ((BitmapSource)_image.Source).PixelHeight
|
||||
};
|
||||
|
||||
return new SizeRequest(result);
|
||||
return _image.Source.GetDesiredSize();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,28 +29,7 @@ namespace Xamarin.Forms.Platform.UWP
|
|||
|
||||
_measured = true;
|
||||
|
||||
if (Control.Source is BitmapSource bitmap)
|
||||
{
|
||||
return new SizeRequest(
|
||||
new Size
|
||||
{
|
||||
Width = bitmap.PixelWidth,
|
||||
Height = bitmap.PixelHeight
|
||||
});
|
||||
}
|
||||
else if (Control.Source is CanvasImageSource canvas)
|
||||
{
|
||||
return new SizeRequest(
|
||||
new Size
|
||||
{
|
||||
Width = canvas.SizeInPixels.Width,
|
||||
Height = canvas.SizeInPixels.Height
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidCastException($"\"{Control.Source.GetType().FullName}\" is not supported.");
|
||||
}
|
||||
return Control.Source.GetDesiredSize();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AccessibilityExtensions.cs" />
|
||||
<Compile Include="Extensions\ImageExtensions.cs" />
|
||||
<Compile Include="IImageVisualElementRenderer.cs" />
|
||||
<Compile Include="ImageButtonRenderer.cs" />
|
||||
<Compile Include="CollectionViewRenderer.cs" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче