Support setting notification tray icon as a png
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
@@ -133,8 +133,8 @@
|
|||||||
</AppxManifest>
|
</AppxManifest>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Assets\Icon-Light.ico" />
|
<Content Include="Assets\notification-icon-light.png" />
|
||||||
<Content Include="Assets\Icon.ico" />
|
<Content Include="Assets\notification-icon.png" />
|
||||||
<Content Include="Properties\Default.rd.xml" />
|
<Content Include="Properties\Default.rd.xml" />
|
||||||
<Content Include="Assets\LockScreenLogo.scale-200.png" />
|
<Content Include="Assets\LockScreenLogo.scale-200.png" />
|
||||||
<Content Include="Assets\SplashScreen.scale-200.png" />
|
<Content Include="Assets\SplashScreen.scale-200.png" />
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:controls="using:TheXamlGuy.NotificationFlyout.Uwp.UI.Controls"
|
xmlns:controls="using:TheXamlGuy.NotificationFlyout.Uwp.UI.Controls"
|
||||||
xmlns:muxc="using:Microsoft.UI.Xaml.Controls">
|
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
|
||||||
|
IconSource="/Assets/notification-icon.png"
|
||||||
|
LightIconSource="/Assets/notification-icon-light.png">
|
||||||
<controls:NotificationFlyout.FlyoutPresenterStyle>
|
<controls:NotificationFlyout.FlyoutPresenterStyle>
|
||||||
<Style TargetType="controls:NotificationFlyoutPresenter">
|
<Style TargetType="controls:NotificationFlyoutPresenter">
|
||||||
<Setter Property="CornerRadius" Value="8" />
|
<Setter Property="CornerRadius" Value="8" />
|
||||||
|
|||||||
@@ -18,16 +18,25 @@ namespace TheXamlGuy.NotificationFlyout.Shared.UI.Extensions
|
|||||||
var uri = $"{AppDomain.CurrentDomain.BaseDirectory}{bitmapImage.UriSource}".Replace("ms-appx:///", "").Replace("/", "\\");
|
var uri = $"{AppDomain.CurrentDomain.BaseDirectory}{bitmapImage.UriSource}".Replace("ms-appx:///", "").Replace("/", "\\");
|
||||||
|
|
||||||
using var stream = File.OpenRead(uri);
|
using var stream = File.OpenRead(uri);
|
||||||
return new Icon(stream, new Size(PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CXICON, dpi), PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CYICON, dpi)));
|
return ExtractIcon(dpi, stream);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var storageFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(bitmapImage.UriSource);
|
var storageFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(bitmapImage.UriSource);
|
||||||
|
|
||||||
using var stream = await storageFile.OpenStreamForReadAsync();
|
using var stream = await storageFile.OpenStreamForReadAsync();
|
||||||
return new Icon(stream, new Size(PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CXICON, dpi), PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CYICON, dpi)));
|
return ExtractIcon(dpi, stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Icon ExtractIcon(uint dpi, Stream stream)
|
||||||
|
{
|
||||||
|
var bitmap = (Bitmap)Image.FromStream(stream);
|
||||||
|
var icon = Icon.FromHandle(bitmap.GetHicon());
|
||||||
|
|
||||||
|
return new Icon(icon, new Size(PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CXICON, dpi), PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CYICON, dpi)));
|
||||||
|
}
|
||||||
|
|
||||||
private enum SystemMetricFlag : int
|
private enum SystemMetricFlag : int
|
||||||
{
|
{
|
||||||
SM_CXICON = 11,
|
SM_CXICON = 11,
|
||||||
|
|||||||
Reference in New Issue
Block a user