// Static constructor. static NamedBrush() { BrushNameProperty = DependencyProperty.Register("BrushName", typeof(string), typeof(NamedBrush), new PropertyMetadata(BrushNameChangedCallback)); BrushProperty = DependencyProperty.Register("Brush", typeof(Brush), typeof(NamedBrush), new PropertyMetadata(BrushChangedCallback)); #if UseArray PropertyInfo[] props = typeof(Brushes).GetProperties(); nbrushes = new NamedBrush[props.Length]; for (int i = 0; i < props.Length; i++) { nbrushes[i] = new NamedBrush(props[i].Name, (Brush)props[i].GetValue(null, null)); } #endif }
private BrushList() { foreach (PropertyInfo pi in typeof(Colors).GetProperties()) { if (pi.PropertyType != typeof(Color)) continue; MethodInfo mi = pi.GetGetMethod(); const MethodAttributes inclusiveAttributes = MethodAttributes.Static | MethodAttributes.Public; if (mi == null || (mi.Attributes & inclusiveAttributes) != inclusiveAttributes) continue; NamedBrush namedBrush = new NamedBrush(pi.Name, (Color)pi.GetValue(null, null)); brushes.Add(namedBrush); } }
void CopyToClipboard(NamedBrush nb) { if (nb != null) { SolidColorBrush scb = nb.Brush as SolidColorBrush; string colorName = nb.ClipboardName; string text = String.Format("{0}=#{4:x02}{1:x02}{2:x02}{3:x02}", colorName, scb.Color.R, scb.Color.G, scb.Color.B, scb.Color.A ); Report("{0}", text); try { Clipboard.SetText(text); } catch { } } }
public Window1() { InitializeComponent(); for (int i = 0; i < frameBackground.Items.Count; ++i) { NamedBrush item = frameBackground.Items[i] as NamedBrush; string[] names = item.BrushName.Split(' '); if (names.Length == 2 && names[names.Length - 1] == "White") { frameBackground.SelectedIndex = i; break; } } clipper = new DispatcherTimer(); clipper.Tick += new EventHandler(clipper_Tick); clipper.Interval = TimeSpan.FromSeconds(1); clipper.Start(); }
private static void BrushChangedCallback(DependencyObject dob, DependencyPropertyChangedEventArgs e) { NamedBrush nb = dob as NamedBrush; }
public static void Add(NamedBrush namedBrush) { if (brushes.Count(nb => nb.Name == namedBrush.Name) <= 0) brushes.Insert(0, namedBrush); }