Files
Shrlalgo.RvKits/WPFluent/Controls/IconElement/ImageIcon.cs

54 lines
1.5 KiB
C#
Raw Normal View History


// ReSharper disable once CheckNamespace
namespace WPFluent.Controls;
/// <summary>
/// Represents an icon that uses an <see cref="System.Windows.Controls.Image"/> as its content.
/// </summary>
public class ImageIcon : IconElement
{
/// <summary>
/// Identifies the <see cref="Source"/> dependency property.
/// </summary>
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; }
/// <summary>
/// Gets or sets the Source on this Image.
/// </summary>
public ImageSource? Source
{
get => (ImageSource?)GetValue(SourceProperty);
set => SetValue(SourceProperty, value);
}
}