using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; namespace DI_Electrical.Views.CustomControl { [TemplatePart(Name = "PART_Icon", Type = typeof(Path))] [TemplatePart(Name = "PART_Content", Type = typeof(ContentPresenter))] public class IconButton : Button { static IconButton() { DefaultStyleKeyProperty.OverrideMetadata( typeof(IconButton), new FrameworkPropertyMetadata(typeof(IconButton))); } #region 依赖属性 // 矢量路径数据 public static readonly DependencyProperty IconDataProperty = DependencyProperty.Register( "IconData", typeof(Geometry), typeof(IconButton), new FrameworkPropertyMetadata(null)); // 图标尺寸 public static readonly DependencyProperty IconSizeProperty = DependencyProperty.Register( "IconSize", typeof(double), typeof(IconButton), new FrameworkPropertyMetadata(16.0)); // 图标位置 public static readonly DependencyProperty IconPlacementProperty = DependencyProperty.Register( "IconPlacement", typeof(Dock), typeof(IconButton), new FrameworkPropertyMetadata(Dock.Left)); // 图标与文字间距 public static readonly DependencyProperty IconMarginProperty = DependencyProperty.Register( "IconMargin", typeof(Thickness), typeof(IconButton), new FrameworkPropertyMetadata(new Thickness(0, 0, 5, 0))); #endregion #region 属性包装器 public Geometry IconData { get => (Geometry)GetValue(IconDataProperty); set => SetValue(IconDataProperty, value); } public double IconSize { get => (double)GetValue(IconSizeProperty); set => SetValue(IconSizeProperty, value); } public Dock IconPlacement { get => (Dock)GetValue(IconPlacementProperty); set => SetValue(IconPlacementProperty, value); } public Thickness IconMargin { get => (Thickness)GetValue(IconMarginProperty); set => SetValue(IconMarginProperty, value); } #endregion } }