示例#1
0
        // Handles selected color changed
        private static void OnSelectedColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ColorGallery gallery = d as ColorGallery;

            // Raise event
            gallery.RaiseEvent(new RoutedEventArgs(ColorGallery.SelectedColorChangedEvent));
            // Set color in gallery
            Color?color = (Color?)e.NewValue;

            gallery.UpdateSelectedColor(color);
        }
示例#2
0
        private static void OnThemeColorsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ColorGallery gal = d as ColorGallery;

            gal.ThemeColors.Clear();
            if (e.NewValue != null)
            {
                foreach (Color color in (e.NewValue as IEnumerable <Color>))
                {
                    gal.ThemeColors.Add(color);
                }
            }
        }
示例#3
0
        /// <summary>
        /// When overridden in a derived class, returns a <see cref="T:System.Windows.DataTemplate"/> based on custom logic.
        /// </summary>
        /// <returns>
        /// Returns a <see cref="T:System.Windows.DataTemplate"/> or null. The default value is null.
        /// </returns>
        /// <param name="item">The data object for which to select the template.</param><param name="container">The data-bound object.</param>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            ListBox          listBox = null;
            DependencyObject parent  = container;

            while (parent != null)
            {
                parent  = VisualTreeHelper.GetParent(parent);
                listBox = parent as ListBox;
                if (listBox != null)
                {
                    break;
                }
            }
            if (listBox != null)
            {
                ColorGallery colorGallery = null;
                while (parent != null)
                {
                    parent       = VisualTreeHelper.GetParent(parent);
                    colorGallery = parent as ColorGallery;
                    if (colorGallery != null)
                    {
                        break;
                    }
                }
                if (colorGallery != null)
                {
                    int index = listBox.Items.IndexOf(item);
                    if (index < colorGallery.Columns)
                    {
                        return(listBox.TryFindResource("GradientColorTopDataTemplate") as DataTemplate);
                    }
                    else if (index >= listBox.Items.Count - colorGallery.Columns)
                    {
                        return(listBox.TryFindResource("GradientColorBottomDataTemplate") as DataTemplate);
                    }
                    else
                    {
                        return(listBox.TryFindResource("GradientColorCenterDataTemplate") as DataTemplate);
                    }
                }
            }
            return(null);
        }