protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); // If the DataObject contains string data, extract it. if (e.Data.GetDataPresent(DataFormats.StringFormat)) { string dataString = (string)e.Data.GetData(DataFormats.StringFormat); // If the string can be converted into a Brush, // convert it and apply it to the ellipse. BrushConverter converter = new BrushConverter(); if (converter.IsValid(dataString)) { Brush newFill = (Brush)converter.ConvertFromString(dataString); Background = newFill; // Set Effects to notify the drag source what effect // the drag-and-drop operation had. // (Copy if CTRL is pressed; otherwise, move.) if (e.KeyStates.HasFlag(DragDropKeyStates.ControlKey)) { e.Effects = DragDropEffects.Copy; } else { e.Effects = DragDropEffects.Move; } } } // e.Handled = true; }
public void SetSizes(double x1, double y1, double x2, double y2, double Thickness, double x3, double y3, string text, string fontWeight, string Color, string Tag) { Line Sizeline = new Line(); SetLine(Sizeline, x1, y1, x2, y2, Thickness, Color, Tag); storyboard = new Storyboard(); TextBlock textBlock = new TextBlock(); textBlock.Text = text; textBlock.Foreground = (Brush)Converter.ConvertFromString(Color); Canvas.SetLeft(textBlock, x3); Canvas.SetTop(textBlock, y3); textBlock.FontWeight = (FontWeight)WConverter.ConvertFromString(fontWeight); Canvas.Children.Add(textBlock); textBlock.Tag = Tag; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { PropertyInfo pi = value as PropertyInfo; SolidColorBrush colorBrush = Brushes.Black; if (pi != null) { BrushConverter conv = new BrushConverter(); colorBrush = conv.ConvertFromString(pi.Name) as SolidColorBrush; } return(colorBrush); }
protected override void OnDragEnter(DragEventArgs e) { base.OnDragEnter(e); // Save the current Fill brush so that you can revert back to this value in DragLeave. _previousFill = Background; // If the DataObject contains string data, extract it. if (e.Data.GetDataPresent(DataFormats.StringFormat)) { string dataString = (string)e.Data.GetData(DataFormats.StringFormat); // If the string can be converted into a Brush, convert it. BrushConverter converter = new BrushConverter(); if (converter.IsValid(dataString)) { Brush newFill = (Brush)converter.ConvertFromString(dataString.ToString()); Background = newFill; } } }