Ejemplo n.º 1
0
        public static Brush ConvertBrush(System.Drawing.Color color)
        {
            var b = new BrushConverter();

            if (b.IsValid(color.Name))
            {
                return(b.ConvertFromString(color.Name) as SolidColorBrush);
            }
            else
            {
                return(b.ConvertFromString("Black") as SolidColorBrush);
            }
        }
        /// <summary>
        /// Gets the data from the drag event converts it to it's brush equivalent and sets the dropped onto items background
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ListItem_Drop(object sender, DragEventArgs e)
        {
            ListViewItem listViewItem = sender as ListViewItem;

            if (listViewItem != null && e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                string         data      = (string)e.Data.GetData(DataFormats.StringFormat);
                BrushConverter converter = new BrushConverter();
                if (converter.IsValid(data))
                {
                    listViewItem.Background = (Brush)converter.ConvertFromString(data);
                }
            }
        }
Ejemplo n.º 3
0
 protected override void OnDragOver(DragEventArgs e)
 {
     base.OnDragOver(e);
     e.Effects = DragDropEffects.None;
     if (e.Data.GetDataPresent(DataFormats.StringFormat))
     {
         var dataString = (string)e.Data.GetData(DataFormats.StringFormat);
         var converter  = new BrushConverter();
         if (dataString != null && converter.IsValid(dataString))
         {
             e.Effects = e.KeyStates.HasFlag(DragDropKeyStates.ControlKey) ? DragDropEffects.Copy : DragDropEffects.Move;
         }
     }
     e.Handled = true;
 }
Ejemplo n.º 4
0
        internal static object CoerceNonNullable(object value, Type targetType, bool ignoreImplicitXamlConversions)
        {
            if (!ignoreImplicitXamlConversions && IsImplicitXamlConvertion(value.GetType(), targetType))
            {
                return(value);
            }
            if (targetType == typeof(string))
            {
                return(value.ToString());
            }
            if (targetType.IsEnum && value is string)
            {
                return(Enum.Parse(targetType, (string)value, false));
            }
            if (targetType == typeof(Color))
            {
                var c = new ColorConverter();
                if (c.IsValid(value))
                {
                    return(c.ConvertFrom(value));
                }
                return(value);
            }
            if (targetType == typeof(Brush) || targetType == typeof(SolidColorBrush))
            {
                var c = new BrushConverter();
                if (c.IsValid(value))
                {
                    return(c.ConvertFrom(value));
                }
                if (value is Color)
                {
                    return(BrushesCache.GetBrush((Color)value));
                }
                return(value);
            }
            var cc = TypeDescriptor.GetConverter(targetType);

            try {
                if (cc != null && cc.IsValid(value))
                {
                    return(cc.ConvertFrom(null, System.Globalization.CultureInfo.InvariantCulture, value));
                }
                return(System.Convert.ChangeType(value, targetType, System.Globalization.CultureInfo.InvariantCulture));
            } catch {
                return(value);
            }
        }
Ejemplo n.º 5
0
 protected override void OnDrop(DragEventArgs e)
 {
     base.OnDrop(e);
     if (e.Data.GetDataPresent(DataFormats.StringFormat))
     {
         var dataString = (string)e.Data.GetData(DataFormats.StringFormat);
         var converter  = new BrushConverter();
         if (dataString != null && converter.IsValid(dataString))
         {
             var newFill = (Brush)converter.ConvertFromString(dataString);
             ClassViewUi.Fill = newFill;
             e.Effects        = e.KeyStates.HasFlag(DragDropKeyStates.ControlKey) ? DragDropEffects.Copy : DragDropEffects.Move;
         }
     }
     e.Handled = true;
 }
Ejemplo n.º 6
0
        private void ellipse_DragOver(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.None;

            // 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, allow copying.
                BrushConverter converter = new BrushConverter();
                if (converter.IsValid(dataString))
                {
                    e.Effects = DragDropEffects.Copy;
                }
            }
        }
Ejemplo n.º 7
0
        protected override void OnDragEnter(DragEventArgs e)
        {
            base.OnDragEnter(e);

            _previousFill = circleUI.Fill;

            if (e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                string dataString = (string)e.Data.GetData(DataFormats.StringFormat);

                BrushConverter converter = new BrushConverter();
                if (converter.IsValid(dataString))
                {
                    Brush newFill = (Brush)converter.ConvertFromString(dataString.ToString());
                    circleUI.Fill = newFill;
                }
            }
        }
Ejemplo n.º 8
0
        protected override void OnDragEnter(DragEventArgs e)
        {
            base.OnDragEnter(e);
            // Save the current Fill brush so that yo can revert back to this value in DragLeave.
            _previousFill = circleUI.Fill;

            //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))
                {
                }
            }
        }
Ejemplo n.º 9
0
        protected override void OnDragEnter(DragEventArgs e)
        {
            base.OnDragEnter(e);
            previousFill = ClassViewUi.Fill;
            if (!e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                return;
            }
            var dataString = (string)e.Data.GetData(DataFormats.StringFormat);
            var converter  = new BrushConverter();

            if (dataString == null || !converter.IsValid(dataString))
            {
                return;
            }
            var newFill = (Brush)converter.ConvertFromString(dataString);

            ClassViewUi.Fill = newFill;
        }
Ejemplo n.º 10
0
        protected override void OnDragEnter(DragEventArgs e)
        {
            base.OnDragEnter(e);
            // Speichere die aktuelle Füllfarbe des Pinsels sodass in DragLeave wieder drauf zugreifen kann.
            _previousFill = schuelerUI.Fill;

            // // Wenn ein Benutzersteuerungselement String-Daten beinhaltet, ziehe diese raus.
            if (e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                string dataString = (string)e.Data.GetData(DataFormats.StringFormat);

                // Sollte der String in einen Pinsel konvertiert werden können, konvertiere.
                BrushConverter converter = new BrushConverter();
                if (converter.IsValid(dataString))
                {
                    Brush newFill = (Brush)converter.ConvertFromString(dataString.ToString());
                    schuelerUI.Fill = newFill;
                }
            }
        }
Ejemplo n.º 11
0
        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);
                    dragElement.Fill = newFill;
                }
            }
            e.Handled = true;
        }
Ejemplo n.º 12
0
        // To enable the user control to be a drop target
        // To process the dropped data
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);
            string dataString = string.Empty;

            // If the DataObject contains string data, extract it.
            if (e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                dataString = (string)e.Data.GetData(DataFormats.StringFormat);
            }
            else //if(e.Data.GetDataPresent(DataFormats.Serializable))
            {
                dataString = (string)e.Data.GetData("Text");
            }

            // if both test are valid
            if (!string.IsNullOrEmpty(dataString))
            {
                // 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);
                    circleUI.Fill = 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;
        }
        private void TextBlockDrop(object sender, DragEventArgs e)
        {
            if (!(sender is TextBlock textBlock) || !e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                return;
            }
            var dataString = (string)e.Data.GetData(DataFormats.StringFormat);
            var converter  = new BrushConverter();

            Debug.Assert(dataString != null, nameof(dataString) + "!= null");
            if (!converter.IsValid(dataString))
            {
                textBlock.Text = "Could not convert '" + dataString + "' into a color";
                dataString     = "LightSteelBlue";
            }
            else
            {
                textBlock.Text = "Color is " + dataString;
            }
            textBlock.Background = (Brush)converter.ConvertFromString(dataString);
        }
Ejemplo n.º 14
0
        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 = dragElement.Fill;

            // 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);
                    dragElement.Fill = newFill;
                }
            }
        }
Ejemplo n.º 15
0
        //To verify that the data drop is allowed
        protected override void OnDragOver(DragEventArgs e)
        {
            base.OnDragOver(e);
            e.Effects = DragDropEffects.None;
            string dataString = string.Empty;

            // If the DataObject contains string data, extract it.
            if (e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                dataString = (string)e.Data.GetData(DataFormats.StringFormat);
            }
            else //if(e.Data.GetDataPresent(DataFormats.Serializable))
            {
                dataString = (string)e.Data.GetData("Text");
            }

            //
            if (!string.IsNullOrEmpty(dataString))
            {
                // If the string can be converted into a Brush, allow copying or moving.
                BrushConverter converter = new BrushConverter();
                if (converter.IsValid(dataString))
                {
                    // Set Effects to notify the drag source what effect
                    // the drag-and-drop operation will have. These values are
                    // used by the drag source's GiveFeedback event handler.
                    // (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;
        }
Ejemplo n.º 16
0
        private void ellipse_Drop(object sender, DragEventArgs e)
        {
            Ellipse ellipse = sender as Ellipse;

            if (ellipse != null)
            {
                // If the DataObject contains string data, extract it.
                if (e.Data.GetDataPresent(DataFormats.StringFormat))
                {
                    string dataString = e.Data.GetData(DataFormats.StringFormat) as string;

                    // 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 = converter.ConvertFromString(dataString) as Brush;
                        ellipse.Fill = newFill;
                    }
                }
            }
        }
        /// <summary>
        /// Handles drag and drop functionality for favourtie color rectangles.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FavoriteRect_DragOver(object sender, DragEventArgs e)
        {
            if (_isEyedropperMode)
            {
                return;
            }

            e.Effects = DragDropEffects.None;

            // 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, allow copying.
                BrushConverter converter = new BrushConverter();
                if (converter.IsValid(dataString))
                {
                    e.Effects = DragDropEffects.Copy | DragDropEffects.Move;
                }
            }
        }
Ejemplo n.º 18
0
        private void Ellipse_DragEnter(object sender, System.Windows.DragEventArgs e)
        {
            if (sender is Ellipse ellipse)
            {
                // Save the current Fill brush so that you can revert back to this value in DragLeave.
                _previousFill = ellipse.Fill;

                // If the DataObject contains string data, extract it.
                if (e.Data.GetDataPresent(System.Windows.DataFormats.StringFormat))
                {
                    string dataString = (string)e.Data.GetData(System.Windows.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);
                        ellipse.Fill = newFill;
                    }
                }
            }
        }
Ejemplo n.º 19
0
        private void Ellipse_Drop(object sender, System.Windows.DragEventArgs e)
        {
            if (sender is Ellipse ellipse)
            {
                Console.WriteLine("Ellipse_Drop entered...");
                // If the DataObject contains string data, extract it.
                if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
                {
                    string[] fileNames = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop);
                    ProcessSelectedFiles(fileNames);

                    // If the string can be converted into a Brush,
                    // convert it and apply it to the ellipse.
                    BrushConverter converter     = new BrushConverter();
                    string         firstFileName = fileNames[0].ToString();
                    if (converter.IsValid(firstFileName))
                    {
                        Brush newFill = (Brush)converter.ConvertFromString(firstFileName);
                        ellipse.Fill = newFill;
                        e.Effects    = System.Windows.DragDropEffects.Copy;
                    }
                }
            }
        }
Ejemplo n.º 20
0
        private void ellipse_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                var dataString = e.Data.GetData(DataFormats.StringFormat) as string;
                var converter  = new BrushConverter();
                if (converter.IsValid(dataString))
                {
                    var newFill = converter.ConvertFromString(dataString) as Brush;
                    var ellipse = (e.Source as Ellipse);
                    ellipse.Fill = newFill;

                    if (e.KeyStates.HasFlag(DragDropKeyStates.ControlKey))
                    {
                        e.Effects = DragDropEffects.Copy;
                    }
                    else
                    {
                        e.Effects = DragDropEffects.Move;
                    }
                }
            }
            e.Handled = true;
        }
Ejemplo n.º 21
0
        // To preview the effects of the drag-and-drop operation
        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 = circleUI.Fill;

            string dataString = string.Empty;

            // If the DataObject contains string data, extract it.
            if (e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                dataString = (string)e.Data.GetData(DataFormats.StringFormat);
            }
            else //if(e.Data.GetDataPresent(DataFormats.Serializable))
            {
                dataString = (string)e.Data.GetData("Text");
            }

            // if both test are valid
            if (!string.IsNullOrEmpty(dataString))
            {
                // If the DataObject contains string data, extract it.
                if (e.Data.GetDataPresent(DataFormats.StringFormat))
                {
                    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());
                        circleUI.Fill = newFill;
                    }
                }
            }
        }