// ReSharper disable once CheckNamespace
namespace WPFluent.Controls;
///
/// Represents an icon that uses an as its content.
///
public class ImageIcon : IconElement
{
///
/// Identifies the dependency property.
///
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register(
nameof(Source),
typeof(ImageSource),
typeof(ImageIcon),
new FrameworkPropertyMetadata(
null,
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender,
OnSourceChanged));
private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ImageIcon self = (ImageIcon)d;
if(self.Image is null)
{
return;
}
self.Image.SetCurrentValue(System.Windows.Controls.Image.SourceProperty, (ImageSource?)e.NewValue);
}
protected override UIElement InitializeChildren()
{
Image = new System.Windows.Controls.Image() { Source = Source, Stretch = Stretch.UniformToFill };
return Image;
}
protected System.Windows.Controls.Image? Image { get; set; }
///
/// Gets or sets the Source on this Image.
///
public ImageSource? Source
{
get => (ImageSource?)GetValue(SourceProperty);
set => SetValue(SourceProperty, value);
}
}