Example #1
0
        /// <summary>
        /// The add color to recent colors if missing.
        /// </summary>
        /// <param name="color">
        /// The color.
        /// </param>
        /// <returns>
        /// True if the color was added.
        /// </returns>
        private bool AddColorToRecentColorsIfMissing(Color color)
        {
            // Check if the color exists
            if (ThemeColors.Contains(color))
            {
                return(false);
            }

            if (StandardColors.Contains(color))
            {
                return(false);
            }

            if (RecentColors.Contains(color))
            {
                return(false);
            }

            if (RecentColors.Count >= this.MaxNumberOfRecentColors)
            {
                RecentColors.RemoveAt(RecentColors.Count - 1);
            }

            RecentColors.Insert(0, color);
            return(true);
        }
Example #2
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (!(GetTemplateChild("PART_MoreColors") is FluentMenuItem moreColors))
            {
                return;
            }
            EventManager.RegisterClassHandler(moreColors.GetType(), MenuItem.ClickEvent, new RoutedEventHandler((s, args) =>
            {
                if (moreColors != s)
                {
                    return;
                }
                var colorChoose = new ColorChooserWindow {
                    Owner = Window.GetWindow(this)
                };
                colorChoose.ActionComplete += (o, eventArgs) =>
                {
                    var color = eventArgs.Color;
                    if (RecentColors.Contains(color))
                    {
                        RecentColors.Remove(color);
                    }

                    RecentColors.Insert(0, color);
                    if (GetTemplateChild("PART_RecentColorsListBox") is ListBox recentColors)
                    {
                        recentColors.SelectedIndex = 0;
                    }
                };
                colorChoose.ShowDialog();
                args.Handled = true;
            }));
        }
Example #3
0
        private void OnMoreColorsClick(object sender, RoutedEventArgs e)
        {
            if (this.MoreColorsExecuting != null)
            {
                var args = new MoreColorsExecutingEventArgs();
                this.MoreColorsExecuting(this, args);
                if (!args.Canceled)
                {
                    var color = args.Color;
                    if (RecentColors.Contains(color))
                    {
                        RecentColors.Remove(color);
                    }

                    RecentColors.Insert(0, color);
                    this.recentColorsListBox.SelectedIndex = 0;
                }
            }
            else
            {
#pragma warning disable 618
                var chooseColor = new CHOOSECOLOR();
                var wnd         = Window.GetWindow(this);
                if (wnd != null)
                {
                    chooseColor.hwndOwner = new WindowInteropHelper(wnd).Handle;
                }

                chooseColor.Flags = CC_ANYCOLOR;
                if (customColors == IntPtr.Zero)
                {
                    // Set custom colors)
                    for (var i = 0; i < this.colorsArray.Length; i++)
                    {
                        this.colorsArray[i] = 0x00FFFFFF;
                    }

                    customColors = GCHandle.Alloc(this.colorsArray, GCHandleType.Pinned).AddrOfPinnedObject();
                }

                chooseColor.lpCustColors = customColors;
                if (ChooseColor(chooseColor))
                {
                    var color = ConvertFromWin32Color(chooseColor.rgbResult);
                    if (RecentColors.Contains(color))
                    {
                        RecentColors.Remove(color);
                    }

                    RecentColors.Insert(0, color);
                    this.recentColorsListBox.SelectedIndex = 0;
                }
#pragma warning restore 618
            }
        }
Example #4
0
 private void OnMoreColorsClick(object sender, RoutedEventArgs e)
 {
     if (MoreColorsExecuting != null)
     {
         MoreColorsExecutingEventArgs args = new MoreColorsExecutingEventArgs();
         MoreColorsExecuting(this, args);
         if (!args.Canceled)
         {
             Color color = args.Color;
             if (RecentColors.Contains(color))
             {
                 RecentColors.Remove(color);
             }
             RecentColors.Insert(0, color);
             recentColorsListBox.SelectedIndex = 0;
         }
     }
     else
     {
         NativeMethods.CHOOSECOLOR chooseColor = new NativeMethods.CHOOSECOLOR();
         Window wnd = Window.GetWindow(this);
         if (wnd != null)
         {
             chooseColor.hwndOwner = new WindowInteropHelper(wnd).Handle;
         }
         chooseColor.Flags = NativeMethods.CC_ANYCOLOR;
         if (customColors == IntPtr.Zero)
         {
             // Set custom colors)
             for (int i = 0; i < colorsArray.Length; i++)
             {
                 colorsArray[i] = 0x00FFFFFF;
             }
             customColors = GCHandle.Alloc(colorsArray, GCHandleType.Pinned).AddrOfPinnedObject();
         }
         chooseColor.lpCustColors = customColors;
         if (NativeMethods.ChooseColor(chooseColor))
         {
             Color color = ConvertFromWin32Color(chooseColor.rgbResult);
             if (RecentColors.Contains(color))
             {
                 RecentColors.Remove(color);
             }
             RecentColors.Insert(0, color);
             recentColorsListBox.SelectedIndex = 0;
         }
     }
 }
Example #5
0
        /// <summary>
        /// The add color to recent colors if missing.
        /// </summary>
        /// <param name="color">The color.</param>
        private void AddColorToRecentColorsIfMissing(Color color)
        {
            // Check if the color exists
            if (RecentColors.Contains(color))
            {
                var index = RecentColors.IndexOf(color);
                RecentColors.Move(index, 0);
                return;
            }

            if (RecentColors.Count >= this.MaxNumberOfRecentColors)
            {
                RecentColors.RemoveAt(RecentColors.Count - 1);
            }

            RecentColors.Insert(0, color);
        }