优化更新代码,添加界面功能并整合
This commit is contained in:
53
WPFluent/Controls/IconElement/ImageIcon.cs
Normal file
53
WPFluent/Controls/IconElement/ImageIcon.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user