/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace dnSpy.Contracts.Images { /// /// Image using to load the correct image depending /// on DPI, zoom and background color /// public sealed class DsImage : Image { static DsImage() => DefaultStyleKeyProperty.OverrideMetadata(typeof(DsImage), new FrameworkPropertyMetadata(typeof(DsImage))); /// /// dependency property /// public static readonly DependencyProperty ImageReferenceProperty = DependencyProperty.Register(nameof(ImageReference), typeof(ImageReference), typeof(DsImage), new FrameworkPropertyMetadata(default(ImageReference))); /// /// Gets/sets the image reference, eg. /// public ImageReference ImageReference { get => (ImageReference)GetValue(ImageReferenceProperty); set => SetValue(ImageReferenceProperty, value); } /// /// Background color attached property /// public static readonly DependencyProperty BackgroundColorProperty = DependencyProperty.RegisterAttached("BackgroundColor", typeof(Color?), typeof(DsImage), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits)); /// /// Gets the background color /// /// Object /// public static Color? GetBackgroundColor(DependencyObject depo) => (Color?)depo.GetValue(BackgroundColorProperty); /// /// Sets the background color /// /// Object /// Value /// public static void SetBackgroundColor(DependencyObject depo, Color? value) => depo.SetValue(BackgroundColorProperty, value); /// /// Background brush attached property /// public static readonly DependencyProperty BackgroundBrushProperty = DependencyProperty.RegisterAttached("BackgroundBrush", typeof(Brush), typeof(DsImage), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits)); /// /// Gets the background brush /// /// Object /// public static Brush GetBackgroundBrush(DependencyObject depo) => (Brush)depo.GetValue(BackgroundBrushProperty); /// /// Sets the background brush /// /// Object /// Value /// public static void SetBackgroundBrush(DependencyObject depo, Brush? value) => depo.SetValue(BackgroundBrushProperty, value); /// /// Zoom attached property /// public static readonly DependencyProperty ZoomProperty = DependencyProperty.RegisterAttached("Zoom", typeof(double), typeof(DsImage), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.Inherits)); /// /// Gets the zoom (1.0 == 100%) /// /// Object /// public static double GetZoom(DependencyObject depo) => (double)depo.GetValue(ZoomProperty); /// /// Sets the zoom (1.0 == 100%) /// /// Object /// Value /// public static void SetZoom(DependencyObject depo, double value) => depo.SetValue(ZoomProperty, value); /// /// Dpi attached property /// public static readonly DependencyProperty DpiProperty = DependencyProperty.RegisterAttached("Dpi", typeof(double), typeof(DsImage), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.Inherits)); /// /// Gets the dpi /// /// Object /// public static double GetDpi(DependencyObject depo) => (double)depo.GetValue(DpiProperty); /// /// Sets the dpi /// /// Object /// Value /// public static void SetDpi(DependencyObject depo, double value) => depo.SetValue(DpiProperty, value); } }