using BS.Shared.DataContracts; using BS.Shared.Extensions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; namespace BeWo.View.Controls { public class DPCtrlIcon : DienstplanerControl { public static readonly DependencyProperty DienstValueProperty = DependencyProperty.Register( "DienstValue", typeof(DienstInfoDC), typeof(DienstplanerControl), new UIPropertyMetadata( (s, e) => { var dc = (DienstInfoDC)e.NewValue; var c = (DPCtrlIcon)s; if (c != null) { if (dc != null) { // rgb2gray converts RGB values to grayscale values by forming a weighted sum of the R, G, and B components: // 0.2989 * R + 0.5870 * G + 0.1140 * B var color = ColorExtensions.FromHexStringDefault(dc.Farbe, Colors.Transparent); var brush = new SolidColorBrush(color); c.BorderBlack.Background = brush; c.BorderBlack.ToolTip = dc.DienstName; c.Foreground = color.IsBrighter(70) ? Brushes.Black : Brushes.White; c.Text = dc.Kurz; } else { c.BorderBlack.ToolTip = string.Empty; c.BorderBlack.Background = Brushes.White; c.Foreground = Brushes.Black; c.Text = string.Empty; } } })); public DPCtrlIcon() { InitializeComponent(); BorderBlack.BorderThickness = new Thickness(1); BorderBlack.CornerRadius = new CornerRadius(4); BorderBlack.Visibility = Visibility.Visible; BorderLight.Visibility = Visibility.Hidden; FontSize = 12; } public DienstInfoDC DienstValue { get { return (DienstInfoDC)GetValue(DienstValueProperty); } set { SetValue(DienstValueProperty, value); } } } }