Skip to content

Commit

Permalink
feat: ImageIconSource
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jun 24, 2021
1 parent 5274d9e commit 452adda
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;

namespace Microsoft.UI.Xaml.Controls
{
public class ImageIconSource : IconSource
{
public ImageSource ImageSource
{
get => (ImageSource)GetValue(ImageSourceProperty);
set => SetValue(ImageSourceProperty, value);
}

public static DependencyProperty ImageSourceProperty { get; } =
DependencyProperty.Register(nameof(ImageSource), typeof(ImageSource), typeof(ImageIconSource), new PropertyMetadata(null, OnPropertyChanged));

internal protected override IconElement CreateIconElementCore()
{
var imageIcon = new ImageIcon();
if (ImageSource is { } imageSource)
{
imageIcon.Source = imageSource;
}
if (Foreground is { } newForeground)
{
imageIcon.Foreground = newForeground;
}
return imageIcon;
}

internal protected override DependencyProperty GetIconElementPropertyCore(DependencyProperty sourceProperty)
{
if (sourceProperty == ImageSourceProperty)
{
return ImageIcon.SourceProperty;
}

return base.GetIconElementPropertyCore(sourceProperty);
}
}
}

0 comments on commit 452adda

Please sign in to comment.