Beispiel #1
0
        private static ColorFormatModel Randomize(ColorFormatModel colorFormat)
        {
            if (colorFormat == null)
            {
                throw new ArgumentNullException(nameof(colorFormat));
            }
            var b = new byte[4];

            s_Rnd.NextBytes(b);
            colorFormat.A = b[0];
            colorFormat.R = b[1];
            colorFormat.G = b[2];
            colorFormat.B = b[3];
            return(colorFormat);
        }
Beispiel #2
0
        private void ReorderButtonDown_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            ColorFormatModel color = ((Button)sender).DataContext as ColorFormatModel;

            if (color == null)
            {
                return;
            }

            var index = ViewModel.ColorFormats.IndexOf(color);

            if (index < ViewModel.ColorFormats.Count - 1)
            {
                ViewModel.ColorFormats.Move(index, index + 1);
            }
        }
        private void ReorderButtonUp_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
        {
            ColorFormatModel color = ((MenuFlyoutItem)sender).DataContext as ColorFormatModel;

            if (color == null)
            {
                return;
            }

            var index = ViewModel.ColorFormats.IndexOf(color);

            if (index > 0)
            {
                ViewModel.ColorFormats.Move(index, index - 1);
            }
        }
        /// <summary>
        /// Saves a collection of colors to a JSON file.  Will overwrite file if it already exists.  The structure of the JSON file is as follows:
        ///
        /// <code>
        /// {
        ///     "Colors": [
        ///         "#AABBCC",
        ///         "#001122",
        ///         ...
        ///     ]
        /// }
        /// </code>
        ///
        /// Where "#AABBCC" is the string representation of the color as determined by the ColorFormatModel.
        /// </summary>
        ///
        /// <param name="fileName">The name of the file to save to</param>
        /// <param name="colors">The collection of colors to export</param>
        /// <param name="formatModel">Model to format the exported colors in</param>
        public static void Save(string fileName, ICollection <Color> colors, ColorFormatModel formatModel)
        {
            if (colors == null)
            {
                throw new NullReferenceException("Color list to serialize must be non-null");
            }

            if (formatModel == null)
            {
                throw new NullReferenceException("ColorFormatModel must be non-null");
            }

            var output = new ColorCollectionOutput();

            output.Colors = new List <string>();

            foreach (Color color in colors)
            {
                output.Colors.Add(formatModel.Convert(color));
            }

            File.WriteAllText(fileName, JsonSerializer.Serialize(output, Options));
        }