Back to Devexpress

ColorPalette.CreateGradientPalette(String, ColorCollection) Method

wpf-devexpress-dot-xpf-dot-editors-dot-colorpalette-dot-creategradientpalette-x28-system-dot-string-devexpress-dot-xpf-dot-editors-dot-colorcollection-x29.md

latest5.8 KB
Original Source

ColorPalette.CreateGradientPalette(String, ColorCollection) Method

Returns a palette filled with gradient colors from specified base colors.

Namespace : DevExpress.Xpf.Editors

Assembly : DevExpress.Xpf.Core.v25.2.dll

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
public static ColorPalette CreateGradientPalette(
    string name,
    ColorCollection source
)
vb
Public Shared Function CreateGradientPalette(
    name As String,
    source As ColorCollection
) As ColorPalette

Parameters

NameTypeDescription
nameString

A String value that specifies the palette name. This value is assigned to the ColorPalette.Name property.

| | source | ColorCollection |

The collection of base colors.

|

Returns

TypeDescription
ColorPalette

A ColorPalette descendant that represents a palette with gradient colors.

|

Remarks

The CreateGradientPalette method creates a new palette with the specified name and generates gradient colors for each base color in source.

Example

The following code sample creates custom palettes and displays them within a ColorEdit control.

xaml
<Window x:Class="DXEditors_ColorEdit.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="400" Width="497"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/core">
    <Grid>
        <Grid.Resources>
            <ResourceDictionary>
                <dxc:ColorToBrushConverter x:Key="ColorToBrushConverter"/>
            </ResourceDictionary>
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <GroupBox Header="Text Color" Grid.Column="0" HorizontalAlignment="Left"
                  Margin="3" Name="groupBox1" VerticalAlignment="Top">
            <Grid>
                <dxe:ColorEdit Name="colorEdit1" Color="Green"/>
            </Grid>
        </GroupBox>
        <GroupBox HorizontalAlignment="Stretch" Header="Text Box" Grid.Column="1"
                  Margin="3" Name="groupBox2" VerticalAlignment="Top">
            <Grid>
                <TextBox Text="Sample text..." Grid.Column="1"
                         Foreground="{Binding Path=Color, ElementName=colorEdit1, Converter={StaticResource ColorToBrushConverter}}"
                         Height="100" Margin="3"
                         Name="textBox1" VerticalAlignment="Top" />                
            </Grid>
        </GroupBox>
    </Grid>
</Window>
csharp
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using DevExpress.Xpf.Editors;

namespace DXEditors_ColorEdit {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();

            // Removes the 'Standard Colors' palette.
            colorEdit1.Palettes.Remove(colorEdit1.Palettes["Standard Colors"]);

            // Adds a custom gradient palette.
            colorEdit1.Palettes.Add(CustomPalette.CreateGradientPalette("Apex Colors", PredefinedColorCollections.Apex));

            // Adds a new palette with three custom RGB colors.
            colorEdit1.Palettes.Add(new CustomPalette("Custom RGB Colors", new List<Color>() {
                Color.FromRgb(150, 18, 30),
                Color.FromRgb(20, 40, 20),
                Color.FromRgb(88, 73, 29) 
            }));
        }
    }
}
vb
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Windows.Controls
Imports System.Windows.Media
Imports DevExpress.Xpf.Editors

Namespace DXEditors_ColorEdit
    Partial Public Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()

            ' Removes the 'Standard Colors' palette.
            colorEdit1.Palettes.Remove(colorEdit1.Palettes("Standard Colors"))

            ' Adds a custom gradient palette.
            colorEdit1.Palettes.Add(CustomPalette.CreateGradientPalette("Apex Colors", PredefinedColorCollections.Apex))

            ' Adds a new palette with three custom RGB colors.
            Dim customColors As List(Of Color) = New List(Of Color)
            customColors.Add(Color.FromRgb(150, 18, 30))
            customColors.Add(Color.FromRgb(20, 40, 20))
            customColors.Add(Color.FromRgb(88, 73, 29))
            Dim palette As CustomPalette = New CustomPalette("Custom RGB Colors", customColors)
            colorEdit1.Palettes.Add(palette)
        End Sub
    End Class
End Namespace

See Also

ColorPalette Class

ColorPalette Members

DevExpress.Xpf.Editors Namespace