mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-07-20 13:45:56 +12:00
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
|
// <copyright file="IconToImageSourceConverter.cs" company="PlaceholderCompany">
|
|||
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|||
|
// </copyright>
|
|||
|
//
|
|||
|
// Copyright (c) 2022-2022 Peter Kirmeier
|
|||
|
|
|||
|
namespace SystemTrayMenu.Utilities
|
|||
|
{
|
|||
|
using System;
|
|||
|
using System.Drawing;
|
|||
|
using System.Globalization;
|
|||
|
using System.Windows;
|
|||
|
using System.Windows.Data;
|
|||
|
using System.Windows.Interop;
|
|||
|
using System.Windows.Markup;
|
|||
|
using System.Windows.Media;
|
|||
|
using System.Windows.Media.Imaging;
|
|||
|
|
|||
|
[ValueConversion(typeof(Icon), typeof(ImageSource))]
|
|||
|
public class IconToImageSourceConverter : MarkupExtension, IValueConverter
|
|||
|
{
|
|||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|||
|
{
|
|||
|
if (value != null)
|
|||
|
{
|
|||
|
// Invalid Icon happens usually only during design time with dummy default data
|
|||
|
Icon icon = value is Icon ? (Icon)value : SystemIcons.Error;
|
|||
|
return Imaging.CreateBitmapSourceFromHIcon(
|
|||
|
icon.Handle,
|
|||
|
Int32Rect.Empty,
|
|||
|
BitmapSizeOptions.FromEmptyOptions());
|
|||
|
}
|
|||
|
|
|||
|
return null!;
|
|||
|
}
|
|||
|
|
|||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
|
|||
|
public override object ProvideValue(IServiceProvider serviceProvider)
|
|||
|
{
|
|||
|
return this;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|